hi all,
I have a string : "links : http://aa.link.com link 2 http://fea.link.com http://feafd.nlin.com all link"
How could i get all url in above string ?
the expected result will be an array with :
[0] : http://aa.link.com link
[1] : http://fea.link.com
[2] : http://feafd.nlin.com
get all url in a string
Moderator: General Moderators
Re: get all url in a string
Welcome to the wonderful world of Regular Expressions:
Code: Select all
<?php
$s = "links : http://aa.link.com link 2 http://fea.link.com http://feafd.nlin.com all link";
while (preg_match('#(https?://[^\s]+)(.*)$#i',$s,$m)) { $links[] = $m[1]; $s = $m[2]; }
print_r($links);
?>