i'm creating a news system for programmers, and when displaying an article I convert \n to <br />. This works just fine until the programmers begin using html's <pre></pre> tags.
The <pre></pre> tags will show the news lines without the conversion. So when the conversion takes place, double spacing occurs!
I came up with this, but it doesn't work:
// take out pre before replacing \n with <br />
$index = 0;
while(preg_match("'<pre>.*</pre>'ms", $article['article']) != "")
{
// pull out the statement
$myStash[$index] = preg_match("'<pre>.*</pre>'ms", $article['article']);
$article['article'] = preg_replace("'<pre>.*</pre>'ms", "{-$i-}", $article['article']);
$index++;
}
// do the replacement
$article['article'] = preg_replace("'\n'", "<br />", $article['article']);
// shove em back in
for($i = 0; $i < $index; $i++)
{
// pull out the statement
$article['article'] = preg_replace("'{-$i-}'", $myStash[$i], $article['article']);
}
echo $article['article'];
The problem i'm getting is...
Regualar expression is empty on this line:
$article['article'] = preg_replace("'\n'", "<br />", $article['article']);
Any suggestions or different ideas to solve this problem?