Basically, when outputting certain data, there will be HTML tags that I need changing using preg_replace. There is only one tag, but it may have a class applied to it.
CODE
<pre>
<pre class="red">
<pre class="blue">
<pre class="red">
<pre class="blue">
Those are the only occurances of PRE that will need to be changed. They need to be changed to;
CODE
<div class="code">
<div class="code red">
<div class="code blue">
<div class="code red">
<div class="code blue">
Which is fair enough ... easily done. But now the tricky part I'm having problems with is applying nl2br() to the code which only appears within those PRE tags.
My current function makes all the tag changes;
PHP
<?php
function ConvertPRE($string) {
$pre = array('<pre>', '</pre>', '<pre class="');
$div = array('<div class="code">', '</div>', '<div class="code ');
return str_replace($pre, $div, $string);
}
?>
function ConvertPRE($string) {
$pre = array('<pre>', '</pre>', '<pre class="');
$div = array('<div class="code">', '</div>', '<div class="code ');
return str_replace($pre, $div, $string);
}
?>
Does anyone have any idea how I can do this?