You are here: Re: regular expressions conditional replace « PHP Language « IT news, forums, messages
Re: regular expressions conditional replace

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация