...

View Full Version : Replcing line breaks with <p></p>?



mat
01-19-2004, 07:27 AM
I have a form which lets the user enter text and add this to the database.
When this text is pulled from mySQL database, I use the function 'nl2br' to convert \r\n to <br>.

So my html text comes out as

This is a paragraph<br><br>
This is another paragraph<br><br>


...but I really need it to come out as:

<p>This is a paragraph</p>
<p>This is another paragraph</p>


Does anyone have suggestions on how to do this ?

Nightfire
01-19-2004, 10:09 AM
<?php
$str = str_replace("\n","</p><p>",$str);
echo '<p> ' . $str . ' </p>';
?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum