XtremeGamer99
09-05-2005, 06:44 PM
Hey. I am having trouble with a preg function.
$text = preg_replace('#(\n*)(.+)(\n*)#i', '<p>$2</p>'."\n", str_replace("\r\n", "\n", $text));
I use that for a news system I am working on. What is does is convert all line breaks to paragraph tags and because of that, it is meant for conent that needs little line brakes, such as news. However, if I were to use the <pre> tag in the content being processed, such as
<pre>
<?php
echo "blah";
?>
</pre>
it would turn it into
<p><pre></p>
<p><?php</p>
<p>echo "blah";</p>
<p>?></p>
<p></pre></p>
Making huge gaps. I am wondering how I can ignore text that is inside a <pre> tag from being processed into a bunch of paragrahs. I was thinking using regex in the code I already have above, but i'm not sure how to do it. Can anyone help?
$text = preg_replace('#(\n*)(.+)(\n*)#i', '<p>$2</p>'."\n", str_replace("\r\n", "\n", $text));
I use that for a news system I am working on. What is does is convert all line breaks to paragraph tags and because of that, it is meant for conent that needs little line brakes, such as news. However, if I were to use the <pre> tag in the content being processed, such as
<pre>
<?php
echo "blah";
?>
</pre>
it would turn it into
<p><pre></p>
<p><?php</p>
<p>echo "blah";</p>
<p>?></p>
<p></pre></p>
Making huge gaps. I am wondering how I can ignore text that is inside a <pre> tag from being processed into a bunch of paragrahs. I was thinking using regex in the code I already have above, but i'm not sure how to do it. Can anyone help?