0

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>

4 Answers 4

2

You don't need regex at all

echo strip_tags( $html, '<b><p>' );
Sign up to request clarification or add additional context in comments.

1 Comment

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!
2

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

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

2 Comments

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

Comments

0
$string = preg_replace('#</?font.*?>#', '', $string);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.