note 41144 added to function.nl2br

From: Date: Wed, 31 Mar 2004 17:08:58 +0000
Subject: note 41144 added to function.nl2br
Groups: php.notes 
Request: Send a blank email to php-notes+get-67424@lists.php.net to get a copy of this message
Here's what I did to format paragraphs and line breaks to XHTML 1.0 standards. In my XHTML document where I'm displaying the value I have it placed between <p></p> tags... example: echo '<p>'.stripslashes($content_fdb).'</p>'; For when the data is submitted to the database I have the following: $content_tdb = addslashes($_POST['content_ff']); /* If content has 2 line breaks close off "</p>" tag and start a new "<p>" */ if(ereg("(\n\r)", $content_tdb)) { $content_tdb = str_replace("\n\r\n", "</p><p>", $content_tdb); } /* All double line breaks have been switched so replace single line breaks with "<br />" tags */ $content_tdb = str_replace("\n", "<br />", $content_tdb); And for when I'm pulling the data back into the Textarea I use the following: /* Format Paragraphs */ $content_fdb = str_replace("</p><p>","\n\r\n",$content_fdb); $content_fdb = str_replace("<br />","\n",$content_fdb); <textarea cols="60" rows="13" name="content_ff">'.stripslashes($content_fdb).'</textarea> This will format the double line breaks with a closing "</p>" tag (because it's already open) then it opens another "<p>" tag for the next paragraph. Single line breaks are converted to "<br />" tags, and this will look just like normal line breaks in the textarea when you are modifying it. Seems to work good for me. ---- Manual Page -- http://www.php.net/manual/en/function.nl2br.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+41144 Delete -- http://master.php.net/manage/user-notes.php?action=delete+41144&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+41144&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#67424) next »