note 14285 added to function.str-replace.php
| From: | php-general at lists dot php dot net | Date: | Wed, 25 Jul 2001 07:31:52 +0000 |
| Subject: | note 14285 added to function.str-replace.php | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-15808@lists.php.net to get a copy of this message | ||
When I did some stuff with MySQL here is what I did to make the output more.. friendly when
displaying the data.
In this example there is "news" data in the database. The $comment variable is where the
info is stored in the function I am using. Now since I'm a nutecase, I want to convert every
cr/lf (note, this took me hours until it finally dawned on me) into a <br /> (XHTML compliant)
and if I had a double <br /> convert that into a new paragraph... Well, here is the code:
$comment = str_replace("\r\n","<br />",$comment);
$comment = str_replace("<br /><br />","< /p>\n<
p>",$comment);
Which makes it output pretty nice code, example:
< p>Is it true?< br />Does it really work?< /p>
< p>REALLY?< /p>
< p>No way. I don't believe it.< br />Should you?< /p>
Sorry about the space there in the paragraph coding in the coed example itself, and in the html
example as well. It's way too late/early for me to fight with this thing. Hope this helps
someone else who is up far to late with no caffiene. :)
http://www.php.net/manual/en/function.str-replace.php