【发布时间】:2010-06-29 08:59:04
【问题描述】:
我有一个正则表达式,它通过 html 内容查找一些曾经有效的关键字,但现在失败了,我不明白为什么。 (正则表达式来自this thread。)
$find = '/(?![^<]+>)(?<!\w)(' . preg_quote($t['label']) . ')\b/s';
$text = preg_replace_callback($find, 'replaceCallback', $text);
function replaceCallback($match) {
if (is_array($match)) {
$htmlVersion = $match[1];
$urlVersion = urlencode($htmlVersion);
return '<a class="tag" rel="tag-definition" title="Click to know more about ' . $htmlVersion . '" href="?tag=' . $urlVersion . '">' . $htmlVersion . '</a>';
}
return $match;
}
错误消息指向 preg_replace_Callback 调用并说:
Warning: preg_replace_callback() [function.preg-replace-callback]: Unknown modifier 't' in /frontend.functions.php on line 43
【问题讨论】:
-
HTML 不是正则语言,因此正则表达式可能不是这里最好的工具。
-
你不应该使用正则表达式来解析 html。见这里:stackoverflow.com/questions/1732348/…