$match = array('~(?:face\=[\'"]?(\w开发者_如何学C+)[\'"]?)~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?
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">');
精彩评论