user198989
user198989

Reputation: 4665

Remove only font tags in a string

I only want to remove tags in my string. But font tags are like

<font face="arial">
<font face="Georgia">
<font face="Tahoma">

...

I used this one but it does not work.

preg_replace('~<font[^>]*\sface="([0-9a-fA-F]{6})"[^>]*>~', '$1', $string);

Upvotes: 0

Views: 1788

Answers (2)

sjs
sjs

Reputation: 9310

Your regex is matching only font names that are exactly 6 characters in length and composed of only digits and the letters A through F (upper or lower case). Try this:

preg_replace('~<font[^>]*\sface="([^"]*)"[^>]*>~', '$1', $string);

I'm assuming that the way this removes the font tag, but preserves the font name is what you intended.

Upvotes: 2

pna
pna

Reputation: 5761

just use strip_tags http://php.net/manual/en/function.strip-tags.php

Upvotes: 3

Related Questions