开发者

How to remove everything but URL PHP [duplicate]

T开发者_JS百科his question already has answers here: Closed 11 years ago.

Possible Duplicate:

Regex to match URL

I know regexp should be able to do this but I can't figure out how to do it. I wan't to be able to search through a string of text and return only the url's. How would you do this in PHP?

Example

hello there everyone visit this link: http://google.com and this one as well http://amazon.com

would return:

http://google.com

http://amazon.com

Any ideas?


This should work:

$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]);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜