Originally posted by sijis
What i have works perfectly, but i'm sure there is a way to make it better because it 'looks' bad.
Eye of the beholder, I suppose, but
#<font(?:\s[^>]*)?>(.*?)</font\s*>#is
And $1 for the replacement seems adequate. Not a lot of difference, really; it works if there are multiple font entities (though not, unfortunately, if they are nested - regexps can't count), it works if the tags and the text between them wrap across lines, if tabs are used instead of spaces, (it doesn't work if the closing tag contains anything extra other than possibly whitespace, but you'll be able to change that if you think it necessary - since when do closing tags have attributes?), it doesn't match "< font", as the start of a font tag, but then neither do browsers.
If could be made more efficient (at the expect of being made more complicated:
#<font(?:\s[^>]*)?>((?:(?!</font\s*>).)*)</font\s*>#is
If you don't want to worry about mismatched <font> and </font> tags, then you can simplify further by using two regexps:
#<font(?:\s[^>]*)?>#i
#</font\s*>#i
Replacing both, of course, with "".
The last method will of course work even if the entities are nested, while the others would need to be repeated until the string no longer changes.
The problem with str_replace of course (as well as being case-sensitive) is that it won't be able to handle any tags that carry attributes or extra whitespace.