2012-02-16 64 views
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; 
    } 
} 

回答

1

我在一個正則表達式測試儀嘗試這樣做,它不會與一個匹配的URL - 在其中,所以我猜它的正則表達式。嘗試在正則表達式中添加一個 - 字符href=("|\')(https?://([-\w\.]+)+(:\d+)?(/([\w-/_\.]*(\?\S+)?)?)?)("|\')。這應該允許 - 在域之後的路徑段中。全部更換將像

$row->text = preg_replace_callback('@href=("|\')(https?://([-\w\.]+)+(:\d+)?(/([\w-/_\.]*(\?\S+)?)?)?)("|\')@', 'replace_links', $row->text); 
+0

謝謝。像魅力一樣工作。 – mcd 2012-02-16 21:26:23