|
Posted by Janwillem Borleffs on 05/16/05 12:50
Mig21 wrote:
> i want to replace all '\n' with "<br />\n" in a text unless it's in
> between <pre></pre> tags. i can't figure out a way to conditionally
> replace anything.
>
<?php
$text =<<<EOT
some text here
<pre>some
more
text here !</pre>
outside
<pre> Inside </pre>
lala
EOT;
$split = preg_split(
"|(<pre>.*</pre>)|Uis",
$text,
-1,
PREG_SPLIT_DELIM_CAPTURE
);
foreach (array_keys($split) as $i) {
if (!stristr($split[$i], "<pre>")) {
$split[$i] = nl2br($split[$i]);
}
}
$text = implode("", $split);
print $text;
?>
JW
Navigation:
[Reply to this message]
|