Hello,
I'm having problems with this expression:
'<a\s+href\s=\s([\"\'])?(?(1)(.?)\1|([\s>]+)).a>'
I'm trying to pass html code and extract all the links.
The code below almost does it in the way I want except that it only grabs one link and then stops, instead of extracting all the links.
I'm obviously just a little out. Run the code below to see what I mean if this isn't clear.
Does someone know what I'm doing wrong please?
Many thanks if you ca help!
Jason
$string = '
<li>
<a href="http://uk.srd.yahoo.com/goo.uk/prince/1/*[url]http://www.princeofwales.gov.uk/[/url]">The <b>Prince</b> of Wales
</a><br><small>
<b>...</b> In the News, Inside. <b>...</b> 17.12.2001: The <b>Prince</b> of Wales launches the Pub Is The Hub<br> guide on a visit to the Yorkshire Dales. The initiative outlines ways in which <b>...</b>
<br>
<font color=#006600>http://www.princeofwales.gov.uk/ </font>
<a href="http://uk.rd.yahoo.com/search3/morewp/?[url]http://uk.google.yahoo.com/bin/query_uk?p=prince&hq=site:www.princeofwales.gov.uk[/url]">[More results from www.princeofwales.gov.uk]</a><p>
</small></li><p>
';
$preg = "'<a\s+href\s=\s([\"\'])?(?(1)(.?)\1|([\s>]+)).a>'";
preg_match_all($preg, $string, $links);
while(list($key,$val) = each($links[2]))
{
//echo "<br>\n key is $kay and";
if(!empty($val))
$match[$key]["pure_link"] = $val;
}
while(list($key,$val) = each($links[0]))
{
//echo "<br>\n key is $kay and";
if(!empty($val))
$match[$key]["full_link"] = $val;
$match[$key]["display_link"] = strip_text($val);
}
echo "<br>\n links is";
print_r($links);
echo "<br>\n match is";
print_r($match);