Chris2k
11-18-2004, 10:11 AM
Hi
I have a text formatting functon that among other things converts line breaks with nl2br($string) but doing this means anything inside <pre> tags becomes double-spaced, so i either want to ignore anything inside <pre> tags or convert <br /> back to /n i tried several things but can't seem to get this working.
function br2nl($str) {
return preg_replace('!<br.*>!iU',"\n",$str);
}
function textFormat($str)
{
# lots of stuff here bbcode etc
$str = nl2br($str);
$str = preg_replace("#\<pre>(.*)\<\/pre>#si", "<pre>".br2nl('\\1')."</pre>", $str);
return $str;
}
Hope that makes sense, although br2nl works on its on, and the expression works if i try something like "<pre>".strtoupper('abc')."</pre>" but they don't want to work together.
grr, why does vBulletin remove slashes in code tags? the preg_replace line looks nothing like that, seems like i can't post it. =\
$str = preg_replace("#\<pre>(.*)\<\/pre>#si", "<pre>".br2nl('\\1')."</pre>", $str);
there ..
I have a text formatting functon that among other things converts line breaks with nl2br($string) but doing this means anything inside <pre> tags becomes double-spaced, so i either want to ignore anything inside <pre> tags or convert <br /> back to /n i tried several things but can't seem to get this working.
function br2nl($str) {
return preg_replace('!<br.*>!iU',"\n",$str);
}
function textFormat($str)
{
# lots of stuff here bbcode etc
$str = nl2br($str);
$str = preg_replace("#\<pre>(.*)\<\/pre>#si", "<pre>".br2nl('\\1')."</pre>", $str);
return $str;
}
Hope that makes sense, although br2nl works on its on, and the expression works if i try something like "<pre>".strtoupper('abc')."</pre>" but they don't want to work together.
grr, why does vBulletin remove slashes in code tags? the preg_replace line looks nothing like that, seems like i can't post it. =\
$str = preg_replace("#\<pre>(.*)\<\/pre>#si", "<pre>".br2nl('\\1')."</pre>", $str);
there ..
