exploding a sting multiple times
Posted: Mon Nov 23, 2009 3:55 am
Hi,
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.
Above is what i currently have. So as you can see in this example there are two link tags which contain a URL and i need to be able to display the URLs that are in that tag.
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!
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!