note 83936 deleted from function.nl2br by thiago

From: Date: Thu, 05 Mar 2009 12:14:06 +0000
Subject: note 83936 deleted from function.nl2br by thiago
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-151514@lists.php.net to get a copy of this message
Note Submitter: info at eruiz dot es ---- @greywyvern - greywyvern - com You wrote: <?php function nl2br_pre($string, $wrap = 40) { $string = nl2br($string); preg_match_all("/<pre[^>]*?>(.|\n)*?<\/pre>/", $string, $pre1); for ($x = 0; $x < count($pre1[0]); $x++) { $pre2[$x] = preg_replace("/\s*<br[^>]*?>\s*/", "", $pre1[0][$x]); $pre2[$x] = preg_replace("/([^\n]{".$wrap."})(?!<\/pre>)(?!\n)/", "$1\n", $pre2[$x]); $pre1[0][$x] = "/".preg_quote($pre1[0][$x], "/")."/"; } return preg_replace($pre1[0], $pre2, $string); } ?> But... this simple line <? $string = preg_replace('/<pre>(.*?)<\/pre>/ise',"'<pre>' . preg_replace('/(<br \/?>)/is','','\\1') . '</pre>'",$string); ?> Does the same that your <? for ($x = 0; $x < count($pre1[0]); $x++) { $pre2[$x] = preg_replace("/\s*<br[^>]*?>\s*/", "", $pre1[0][$x]); $pre2[$x] = preg_replace("/([^\n]{".$wrap."})(?!<\/pre>)(?!\n)/", "$1\n", $pre2[$x]); $pre1[0][$x] = "/".preg_quote($pre1[0][$x], "/")."/"; } return preg_replace($pre1[0], $pre2, $string); ?> Or not?

« previous php.notes (#151514) next »