2012-05-06 53 views
-1

需要聯繫我下面的PHP代碼來檢測和更換鏈接:PHP腳本檢測jQuery的

//Detect links 
    $pattern_url='~(?>[a-z+]{2,}://|www\.)(?:[a-z0-9]+(?:\.[a-z0-9]+)[email protected])?(?:(?:[a-z](?:[a-z0-9]|(?<!-)-)*[a-z0-9])(?:\.[a-z](?:[a-z0-9]|(?<!-)-)*[a-z0-9])+|(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))(?:/[^\\/:?*"<>|\n]*[a-z0-9])*/?(?:\?[a-z0-9_.%]+(?:=[a-z0-9_.%:/+-]*)?(?:&[a-z0-9_.%]+(?:=[a-z0-9_.%:/+-]*)?)*)?(?:#[a-z0-9_%.]+)?~i'; 
    preg_match_all($pattern_url, $post, $matches); 
    for ($i=0; $i < count($matches[0]); $i++) 
    { 
     if(substr($matches[0][$i],0,4)=='www.') 
     $post = str_replace($matches[0][$i],'http://'.$matches[0][$i],$post); 
    } 
    $post = preg_replace($pattern_url,'<a target="_blank" href="\\0">\\0</a>', $post); 

我想有在JavaScript/jQuery的相同。

這怎麼可能?

+2

正確的答案應該是'在javascript'實現它:) – hochl

回答