tags:

views:

32

answers:

1

$match = array('~(?:face\=[\'"]?(\w+)[\'"]?)~i', '~~i');
$replace = array('font-family:$1;', '<span style="$1">');

I want to replace the old <font> element which has a "face" attribute with a new <span> element with "style" attribute but the regex always fail when the font name in the "face" attribute contains whitespace, e.g : Courier New. How can I modify the regex to solve this problem?

A: 

Replace your \w+ with .+ to include all characters instead of just 'word' characters. Or all characters except ' like this: [^\']+

Updated version:

$match = array('~(?:face\=[\'"]?([^\']+)[\'"]?)~i', '~~i');
$replace = array('font-family:$1;', '<span style="$1">');
John Weldon
Thank you John very much for your answer ;)
You're welcome.
John Weldon