我有一个包含 URL 和其他文本的字符串。我想将所有 URL 放入$matches
数组中。但是以下代码不会将所有 URL 放入$matches
数组中:
$matches = array();
$text = "soundfly.us schoollife.edu hello.net some random news.yahoo.com text http://tinyurl.com/9uxdwc some http://google.com random text http://tinyurl.com/787988 and others will en.wikipedia.org/wiki/Country_music URL";
preg_match_all('$\b(https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|]$i', $text, $matches);
print_r($matches);
上面的代码将得到:
http://tinyurl.com/9uxdwc
http://google.com
http://tinyurl.com/787988
.
但错过了以下 4 个网址:
schoollife.edu
hello.net
news.yahoo.com
en.wikipedia.org/wiki/Country_music
你能告诉我一个例子,我怎样才能修改上面的代码来获取所有的 URL