note 83936 added to function.nl2br
| From: | info at eruiz dot es | Date: | Thu, 19 Jun 2008 15:28:15 +0000 |
| Subject: | note 83936 added to function.nl2br | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-140588@lists.php.net to get a copy of this message | ||
@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?
----
Server IP: 80.64.47.13
Probable Submitter: 217.127.49.215
----
Manual Page -- http://www.php.net/manual/en/function.nl2br.php
Edit -- https://master.php.net/note/edit/83936
Del: integrated -- https://master.php.net/note/delete/83936/integrated
Del: useless -- https://master.php.net/note/delete/83936/useless
Del: bad code -- https://master.php.net/note/delete/83936/bad+code
Del: spam -- https://master.php.net/note/delete/83936/spam
Del: non-english -- https://master.php.net/note/delete/83936/non-english
Del: in docs -- https://master.php.net/note/delete/83936/in+docs
Del: other reasons-- https://master.php.net/note/delete/83936
Reject -- https://master.php.net/note/reject/83936
Search -- https://master.php.net/manage/user-notes.php