URL やその他のテキストを含む文字列があります。$matches
すべての URL を配列に取得したいと考えています。ただし、次のコードではすべての 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 つの URL がありません。
schoollife.edu
hello.net
news.yahoo.com
en.wikipedia.org/wiki/Country_music
上記のコードを変更してすべての URL を取得するにはどうすればよいか、例を挙げて教えてください。