tags:

views:

40

answers:

4

I need to write a regular expression using php which parses the following code block and removes all <font> and </font> tags.

<p align="left"><font face="Arial" size="1">February 22, 2007</font></p> <p align="left"><b><font face="Arial" size="4">2K Sports Announces Major League Baseball 2K7 Has Gone Gold </font></b></p>

+2  A: 

$myString = preg_replace("/<([\/]*)font(.*?)>/","",$myString); should do the trick.

Edit: Just added some magic I forgot earlier... ashes upon me :)

Martin Hohenberg
You're not using the values you find so no need for the capturing parentheses.
kemp
You are correct. I habitually use them nonetheless because I find the regex easier to read with them.
Martin Hohenberg
+1  A: 
preg_replace('!</?font.*?>!', '', $string);
camomileCase
A: 
$string = preg_replace('#</?font.*?>#', '', $string);
kemp
+2  A: 

You don't need regex at all

echo strip_tags( $html, '<b><p>' );
Peter Bailey
this answer rocks!
Jonathan Kushner
Which (depending on what implementation of PHP you have) invokes PCRE or (ghast) others. When will this madness end? Why will the masses not just use an XML parser? What happens if the input changes???? ARGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG!
Tim Post