in reply to Re^2: I need help with displaying newline or paragraph using perl on my website
in thread I need help with displaying newline or paragraph using perl on my website

Depends on what you mean by "get help" -- if you mean 'do it for you,' hire a programer. If you mean help fix your code, you'll have to show it to us, and not just say "it did not work."

But if you mean 'get help learning how to....' -- well, http://www.perlmonks.com/index.pl?node=Tutorials#Pattern-Matching-Regular-Expressions-and-Parsing is just awaiting your visit.

And in that same vein, I'm not clear what you $text looks like, coming out of the database, so can't even guess why the snippet you show does "not work."

However, another and better option might be to stick the text into the db with html markup...

<p>para 1</p> <p>Slightly more extensive para two:</p> <ol><li>with details</li> <li>with details</li> </ol> <p>Pare 3 loret ipsum etc....</p>

That:

para 1

Slightly more extensive para two:

  1. with details
  2. with details

Pare 3 loret ipsum etc....

combined with whatever escaping demanded by your code, should do the job.

BTW, re the first reply, above, <br /> is NOT para code as the node might seem to suggest. It's an entity which produces a single linebreak (like 0d, 0a in a windows file) but not a para break which puts in an extra linebreak so paras are separated by a line blank except for the newline.


check Ln42!

Replies are listed 'Best First'.
Re^4: I need help with displaying newline or paragraph using perl on my website
by 5plit_func (Beadle) on Jun 29, 2014 at 20:28 UTC
    Here is the code i am working on i hope this helps explain what i am trying to achieve.
    #!"c:/xampp/perl/bin/perl.exe" use strict; use warnings; use diagnostics; use CGI::Carp qw{fatalsToBrowser}; use CGI; use DBI; my $query = new CGI; print($query->header()); my $article_id = undef; #check if the article_id parameter has been set if not die immediately if($query->param('article_id') eq "") { die("No parameter submited via the get method so this script most +die here"); }else { $article_id = clean($query->param('article_id')); &db_connect(); &process_article(); } #Create a subroutine that cleans the data submited via the get method sub clean { my $get = shift(@_); $get =~ s/['\.\/-]*//g; if(!int($get)) { die('Invalid parameter submited Script most die here'); } return($get); } my $dbh; #A subroutine for the database connection sub db_connect { my($database,$db_server,$user,$password) = ('closewalk','localhost +','root','' ); $dbh = DBI->connect("DBI:mysql:$database:$db_server",$user,$passwo +rd) || die("$!"); } #A subroutine that processes and displays the article sub process_article { my $statement = qq{select article_id,DATE_FORMAT(date_added,'%D %M + %Y') as date,article_title,author_id,image,message from article wher +e article_id = '$article_id'}; my $sth = $dbh->prepare($statement) || die("Cannot prepare the sql + statement for execution : $dbh->errstr()"); my $rv = $sth->execute() || die("Cannot execute the statement for +process_article : $dbh->errstr()"); my @data; (@data = $sth->fetchrow_array()) || die("Cannot fetch the row of d +ata from the database: $dbh->errstr()"); my($article_id,$date_added,$article_title,$author_id,$image,$messa +ge) = @data; $message =~s/\n/<br \/>/; print( ' <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <link rel="stylesheet" type="text/css" href="/business/religious_semon +s.css" media="screen" /> <title>'.$article_title . '</title> </head> <body> <div id="wrapper"> <div id="text"> <h3>Todays Bible Qoute:</h3> <marquee behavior="alternate">For sin shall not have dominion over you +; for ye are not under the law but under grace</marquee> </div> <div id="box_top"> <div id="logo"> <h1><a href="#">CloseWalk</a></h1> </div> <div id="slogan"> <h3><q>Welcome To CloseWalk a Christian article/sermon website that he +lp you build your faith and relationship with the almight God.</q></h +3> </div> </div><!--close of box_top division--> <div id="navigation"> <ul> <li><a href="#">Home</a></li> <li><a href="#">Articles</a></li> <li><a href="#">Sermons</a></li> <li><a href="#">Testimony</a></li> <li><a href="#">Online Store</a></li> </ul> </div> <div id="latest"> <h1>Latest Articles</h1> <div id="holder"> <figure> <img src="../html/images/6-1-Where-is-Your-Hope.jpg" width="210" heigh +t="150" /> </figure> <h2><a href="#">This is the lords doing and it is marvelouse in our si +te</a></h2> </div> <div id="holder"> <figure> <img src="../html/images/6-13-Believe-in-the-Holy-Spirit.jpg" width="2 +10" height="150" /> </figure> <h2><a href="#">God\'s own University which all men most pass throughs +</a></h2> </div> <div id="holder"> <figure> <img src="../html/images/imagesforchurch/worship2.jpg" width="210" hei +ght="150" /> </figure> <h2><a href="#">God has what it takes to set the captive free</a></h2> </div> <div id="holder"> <figure> <img src="../html/images/imagesforchurch/Family-Worship-Background.jpg +" width="210" height="150" /> </figure> <h2><a href="#">I am my house hold shall serve the almighty God</a></h +2> </div> </div><!--close of latest division of this site --> <div id="body"> <div id="semon"> <h1>'.$article_title.'</h1> <hr /> <span><strong>Published: </strong>'.$date_added . '</span> <div id="image"> <figure> <img src="/cgi-bin/image.pl?image='.$image .'" width="220" height="150 +" /> </figure> </div> <p>' .$message. '</p> '); &author_profile($author_id); print( ' </div><!--close of sermon division --> <div id="advert"> <div id="guest"> <h1>Guest Writer</h1> <figure title="Todays Guest Writer"> <img src="../html/images/imagesforchurch/jesus-name-wallpaper-01.jpg" +width="308" height="120" alt="Guest Writer" /> </figure> <h2><a href="#" class="title">A woman has to be a cover for her family + at all times and she has to grow into a virtues woman</a></h2> <p>So while it’s not inappropriate to explore the path of spiritual gr +owth, we must avoid turning that path into a journey we can engineer +on our own, and we must take care not to turn these stages into tools + to judge others or ourselves. <br /><br /> <a href="#" class="link">Read More</a> </p> </div><!--close of guest division of this site --> </div><!--close of advert division --> </div><!--close of body division --> <div id="footer"> <h1>&copy;CloseWalk.com All Right Reserved 2014</h1> <div id="links" align="center"> <a href="#">About Us</a> <a href="#">Contact Us</a> <a href="#">links</a> <a href="#">partners</a> <a href="#">Advertise with us</a> </div> </div> </div><!--close of wrapper division --> </body> </html> '); } sub author_profile { my $author_id = shift(@_); my $statement = qq{select title,f_name,l_name,profile,image from a +uthor where author_id = '$author_id'}; my $sth = $dbh->prepare($statement) || die("Cannot prepare author +statement for execution : $dbh->errstr()"); my $rv = $sth->execute() || die("Cannot execute author profile sta +tement: $dbh->errstr()"); my @data; (@data = $sth->fetchrow_array()) || die("Cannot fetchrow_array of +author_profile"); my ($title,$f_name,$l_name,$profile,$image) = @data; print(' <div id="author"> <h1>About this author</h1> <figure> <img src="/cgi-bin/author_photo.pl?image='.$image.'" width="180" heigh +t="180" /> </figure> <div id="profile"> <h5>'.ucfirst($title).' '.ucfirst($f_name) .' '. ucfirst($l_name) .'</ +h5> <p>'.$profile. '</p> </div> </div>'); }