note 62855 added to function.nl2br
| From: | chayden at chayden dot com | Date: | Fri, 10 Mar 2006 23:07:00 +0000 |
| Subject: | note 62855 added to function.nl2br | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-105246@lists.php.net to get a copy of this message | ||
Using buzoganylaszlo at yahoo dot com simple nl2p function, I've written a more HTML compliant
function to deal with line breaks ...
<?php
/* FORMATS LINE BREAKS WITH PROPER HTML TAGS */
function format_html($content)
{
$content = "<p>" . str_replace("\r\n", "<br/>",
$content) . "";
$content = "" . str_replace("<br/><br/>",
"</p><p>", $content) . "";
return "" . str_replace("<br/><li>", "<li>",
$content) . "";
}
?>
Here is an example of its use ...
<?php
/* CONTENT TO BE PROCCESSED */
$content = "This is a\r\nline break.\r\n\r\nAnd this is a new paragraph.";
/* USE OF format_html FUNCTION */
/* NOTE: If you want 100% proper HTML tags, you'll need to add a closing paragraph tag
(</p>) as shown below. */
echo format_html("$content</p>");
?>
The above will print ...
<p>This is a
<br/>line break.
<p>And this is a paragraph.</p>
----
Server IP: 216.194.113.175
Probable Submitter: 69.9.253.78
----
X-Spam-Status: No, hits=4.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER,
HTML_30_40,HTML_MESSAGE autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.nl2br.php
Edit -- http://master.php.net/note/edit/62855
Del: integrated -- http://master.php.net/note/delete/62855/integrated
Del: useless -- http://master.php.net/note/delete/62855/useless
Del: bad code -- http://master.php.net/note/delete/62855/bad+code
Del: spam -- http://master.php.net/note/delete/62855/spam
Del: non-english -- http://master.php.net/note/delete/62855/non-english
Del: in docs -- http://master.php.net/note/delete/62855/in+docs
Del: other reasons-- http://master.php.net/note/delete/62855
Reject -- http://master.php.net/note/reject/62855
Search -- http://master.php.net/manage/user-notes.php