tylerjca
06-14-2006, 05:14 AM
I've been trying to get this for the last 2 hours now and I can't seem to get the right pattern for this.
I'm trying to make it so if certain tags are replaced with new ones, and if <br> is found before, or after any of the original tags, it takes them out.
for example, i would want the following text...
$text = 'this is my text<br><br>here is some text<br><br>';
changed to..
$text = 'this is my text<div class=display>here is some text</div>';
Here's what I have so far..
$text = preg_replace("/(<br>)\[code\](<br>)(.*?)(<br>)\[\/code\](<br>)/ism","\n<div style='width:50%;background-color:#cccccc;'>$3</div>\n",$text);
But the problem is that the above code only works if the <br>'s are there in each case. I want it to do the change even if the <br>'s are not there.
I've been reading about the regular expressions but I just can't figure it out:confused:
I'm trying to make it so if certain tags are replaced with new ones, and if <br> is found before, or after any of the original tags, it takes them out.
for example, i would want the following text...
$text = 'this is my text<br><br>here is some text<br><br>';
changed to..
$text = 'this is my text<div class=display>here is some text</div>';
Here's what I have so far..
$text = preg_replace("/(<br>)\[code\](<br>)(.*?)(<br>)\[\/code\](<br>)/ism","\n<div style='width:50%;background-color:#cccccc;'>$3</div>\n",$text);
But the problem is that the above code only works if the <br>'s are there in each case. I want it to do the change even if the <br>'s are not there.
I've been reading about the regular expressions but I just can't figure it out:confused: