Skip to content Skip to sidebar Skip to footer

Parse Elements From Href Tags

I need some help with my code. I want to parse each element from the streams tags but I cant find out how I could do this. When I try this: $streams_url = $xpath->query('//span[

Solution 1:

Since you have the id you are looking for, you don't actually need to use XPath. This will do the job:

$el = $domdoc->getElementById('streams');
$url = $el->getAttribute('href');

In comments you mention you have duplicate id values: this is invalid HTML. But you could process them as follows:

$streams_url = $xpath->query("//*[@id='streams']");
foreach($streams_urlas$a) {
    $url[] = $a->getAttribute("href");
}
print_r($url); // array of href values

Post a Comment for "Parse Elements From Href Tags"