0
我知道正則表達式應該能夠做到這一點,但我無法弄清楚如何做到這一點。我無法搜索一串文本並只返回網址。你將如何在PHP中做到這一點?
例
hello there everyone visit this link: http://google.com and this one as well http://amazon.com
將返回:
任何想法?
我知道正則表達式應該能夠做到這一點,但我無法弄清楚如何做到這一點。我無法搜索一串文本並只返回網址。你將如何在PHP中做到這一點?
hello there everyone visit this link: http://google.com and this one as well http://amazon.com
將返回:
任何想法?
這應該工作:
$text = "hello there everyone visit this link: http://google.com and this one as well http://amazon.com";
preg_match_all('/\b(([\w-]+:\/\/?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|\/)))/',$text,$matches);
print_r($matches[0]);
謝謝,很有魅力。我討厭寫正則表達式 – vincentieo
見http://stackoverflow.com/questions/1141848/regex-to-match-url –
[URL正則表達式(http://www.google.com/搜索?sourceid = chrome&ie = UTF-8&q = url%20regex) – Xeoncross