1
我正在使用舊的Joomla!插件(我知道,第一個錯誤)。它通過正則表達式替換一些URL。下面是代碼:PHP正則表達式修改
$row->text = preg_replace_callback('@href=("|\')(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)("|\')@', 'replace_links', $row->text);
的問題是,它與具有在其中一個連字符的URL打破。任何關於如何修改它以接受連字符的幫助都很棒。
它也可能是replace_links
功能,打破:
function replace_links($matches) {
$match = $matches[0];
$array = array('href=',"'", '"');
$match = str_replace($array, '',$match);
if (strpos($match, JURI::root())) {
return $matches[0];
} else {
$plugin =& JPluginHelper::getPlugin('content', 'linkdisclaimer');
$pluginParams = new JParameter($plugin->params);
$id = $pluginParams->get('disclaimerPage');
$match = "href=\"javascript:linkDisclaimer('".rawurlencode($match)."', '".$id."');\"";
return $match;
}
}
謝謝。像魅力一樣工作。 – mcd 2012-02-16 21:26:23