开发者

Regex fails with whitespace

$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">');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜