I have a string which will contain an unknown amount of URLs in it in html format and i need to explode this string and get all the URLs from it.
Code: Select all
<?php
$string = "bla bla bleh <a href='http://www.link.com'>link name</a> blek bla bla <a href='http://www.linkage.com'>link name</a> blek bla bla";
for($i=0;$i<2;$i++){
$exp = explode("<a href='", $string);
$exp2 = explode("'>", $exp[1]);
echo $exp2[0];
echo "<br />";
}
?>
The above works to an extent in the sense that it lists two links but its listing http://www.link.com twice instead of http://www.link.com and http://www.linkage.com
Any ideas?
Cheers!