I have a string that contain URLs and other texts. I want to get all the URLs in to $matches
array. But the following code wouldn't get all the URLs in to $matches
array:
$matches = array();
$text = "words cotry.lk and newe.com joemiller.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[-A-Z0-9+&@#/%?=~_|!:,.;][.]*[-A-Z0-9+&@#/%=~_|(https?|ftp|file)://-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%?=~_|!:,.;]{8,50}$i', $text, $matches);
print_r($matches);
Above code wouldn't show me following URLs:
cotry.lk
newe.com
Can you please tell me with an example, how can I modify above code to get all the URLs.
Please note, not all the URLs will contain herf and this string is not obtain from a html file.