Basically, I wrote a function that'd take a string, apply the nl2br function to it, but also leave any content contained in between pre tags alone.
For example:
Normal content/n
Normal content/n
<pre>Pre'ed content/n
Pre'ed content/n
Pre'ed content</pre>/n
Normal content/n
Normal content/nWould become:
Normal content<br />
Normal content<br />
<pre>Pre'ed content/n
Pre'ed content/n
Pre'ed content</pre><br />
Normal content<br />
Normal content<br />This is the function I wrote:
#Applies nl2br to $text, but also makes sure to avoid applying the function to any content within pre tags
function nl2brex($text) {
if(!stripos($text, '<pre>', $prevpos)){
$text = nl2br($text);
return $text;
}
$prevpos = 0;
$finaltext = '';
while (strlen($finaltext) <= strlen($text)) {
$preposition = stripos($text, '<pre>', $prevpos);
$splittedstring = substr($text, $prevpos, $preposition);
$splittedstring = nl2br($splittedstring);
$finaltext .= $splittedstring.'***before pre***';
$afterpreposition = stripos($text, '</pre>', $preposition) + 6;
$splittedstring = substr($text, $preposition, $afterpreposition).'***after pre***';
#msgbox($afterpreposition);
#msgbox(strlen($text));
$finaltext .= $splittedstring;
$prevpos = $afterpreposition;
}
return $finaltext;
}The function, unfortunately, doesn't work correctly. For some reason, it isn't catching the </pre> tag, and appending the ***after pre*** to the end of the entire string, instead of right after the </pre> tag. The reason why I have the *** before/after pre *** appended is to assist in debugging, when I was trying to figure out why the function wasn't operating as expected. You can see the results of the function being applied here:
http://bnetdocs.dementedminds.net/?op=packet&pid=237Scroll down to view the first comment, and you'll see what I'm talking about.
If there's a better/more efficient way to accomplish the task, I'm open to alternatives.