Forum Moderators: coopster
$string = 'This is a <a href="www.site.com">string</a> of text with 2 URL's, one of which is [site2.com';...]
I want code that gives this array:
$url_array = array('www.site.com' , 'http://site2.com')
$string = 'This is a <a href="www.site.com">string</a><br />';
$string .= '<a href="monkey.html">monkey</a> fishsticks';
$found = array();
$pattern = '/<a href="(.*)">.*<\/a>/iU';
[url=http://us3.php.net/manual/en/function.preg-match-all.php]preg_match_all[/url]($pattern,$string,$found);
$urls = $found[1];
echo '<pre>';
print_r($urls);
echo '</pre>';
Good luck!
preg_match() will stop searching after the first match. preg_match_all() on the contrary will continue until it reaches the end of subject.