tiger0516
asked on
Use regular expression to remove all <font> tags
I have lots of pages and there are tons of <font size=... ... color =... ...> ... </font> tags. I want to remove all of them. Just keep the text between <font> and </font>
How do I use preg_replace to move all those tags?
Thanks,
How do I use preg_replace to move all those tags?
Thanks,
ASKER
Thanks
But this is a White-List solution, I'd like a Black-List solution.
But this is a White-List solution, I'd like a Black-List solution.
<<But this is a White-List solution, I'd like a Black-List solution.>>
??
Can you elaborate and give more details ob what you want to achieve?
??
Can you elaborate and give more details ob what you want to achieve?
To simply remove all instances of <font...> or </font>
<?php
$string = '<font color="red"><font><font size="2">text</font> more text</font> and more text</font>';
while(preg_match('/<\/?font[^>]*>/i', $string, $matches)) {
$string = str_replace($matches[0], '', $string);
}
echo $string;
?>
ASKER
ok.
php's strip_tags gives a list of ALLOWED tags and remove all others
I want to give a list of NOT ALLOWED tags and keep all others.
php's strip_tags gives a list of ALLOWED tags and remove all others
I want to give a list of NOT ALLOWED tags and keep all others.
ASKER
Thanks Hube02
What about if users leave a space?
eg:
< font >
< font>
< /font>
...
What about if users leave a space?
eg:
< font >
< font>
< /font>
...
Don't know what I was thinking with that while loop, the loop is not needed. preg_replace will replace all occurrences by default, so all you need is:
$string = preg_replace('/<\/?font[^> ]*>/', '', $string);
$string = preg_replace('/<\/?font[^>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I should mention however that that will also replace something like
< font tags are not wanted >
However, I find it hard to think of why someone would use angel brackets and the word font or fonts in a sentence.
< font tags are not wanted >
However, I find it hard to think of why someone would use angel brackets and the word font or fonts in a sentence.
http://us.php.net/strip_tags
$string = strip_tags($string, "<p><a><img><script><div><