Wrap <p></p> tags around text called from DB?

Hello,

Quick question. Say I caled a ‘text’ field in MYSQL and it has a large amount of text in it like so

Lorem ipsum dolor sit amet, consectetur adipiscing elit. In vel erat ligula, molestie rhoncus ligula. Integer quis nisi libero.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur pretium hendrerit mi, eget laoreet nunc vehicula vel.
Duis luctus posuere risus, a ultricies massa porta et. Ut consectetur neque quis massa mollis vehicula aliquet nunc mollis.

How could I call it out of the database so it had <p></p> tags around it like so? I know that nl2br chucks a <br /> tag, but how do you make it so it goes like so:

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. In vel erat ligula, molestie rhoncus ligula. Integer quis nisi libero.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur pretium hendrerit mi, eget laoreet nunc vehicula vel.</p>
<p>Duis luctus posuere risus, a ultricies massa porta et. Ut consectetur neque quis massa mollis vehicula aliquet nunc mollis.</p>

Thanks

if ($line[0]) {

This (above) will always be true, basically if $line[0] exists. What you want is increment and if($i == 1) make it bold since $i will only be 1 one time.

Thanks!

Use this type of foreach loop:


foreach (array_expression as $key => $value)

and then in the ‘if’ check if the $key == 0.

Thanks, that’s a good idea. Done that, but want to make the first line bold, any idea why it’s making all likes bold:


$lines = explode("\\r\
",$row["story"]);

foreach ($lines as $line) {

  if ($line[0]) {
    echo "<p><strong>".$line."</p></strong>\
"; 
  } else {
    echo "<p>".$line."</p>\
";   
  }
}

You could explode the text, obtaining an array of lines. Then, [URL=“http://www.php.net/manual/en/control-structures.foreach.php”]loop through the array and display each line with the <p> tags.