note 41144 deleted from function.nl2br by tomsommer

From: Date: Wed, 31 Mar 2004 23:13:26 +0000
Subject: note 41144 deleted from function.nl2br by tomsommer
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-67438@lists.php.net to get a copy of this message
Note Submitter: Jeff ---- 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.

« previous php.notes (#67438) next »