除了URL PHP之外,如何删除所有内容

时间:2011-08-23 19:48:50

标签: php

  

可能重复:
  Regex to match URL

我知道regexp应该可以做到这一点,但我无法弄清楚如何做到这一点。我不能搜索一串文字并仅返回网址。你会怎么用PHP做这个?

实施例

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

将返回:

http://google.com

http://amazon.com

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

这应该有效:

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