我想用某種形式的正則表達式來提取任何類型的鏈接像www.google.com或http://google.com或https://google.com或只是從一個字符串google.com
我已經使用這樣的東西..但它只檢測鏈接與http和https
$regex ="/(https?:\/\/[^\s]+)/";
$string ="is there a link http://google.com in this string?";
preg_match($regex, $string,$matches);
print_r($matches);
我得到的輸出是
Array ([0] => http://google.com)
我想檢測所有類型的字符串中的可能聯繫。
任何幫助將不勝感激! :)
還有其他幾個參考文獻。搜索此網站獲取'[php] preg_match網址' –
我不認爲這是鏈接問題的完全重複。 OP想要覆蓋更多的鏈接模式,並且給定的鏈接不會幫助OP。 – stema