从href标签中解析元素

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[@id='streams'"]);

I will get something like this:

serverip page isn’t working

serverip is currently unable to handle this request.

HTTP ERROR 500

Here is the php:

<?php
ini_set('max_execution_time', 300);
$errmsg_arr = array();
$errflag = false;

function getState($string)
{
  $ex = explode(" ",$string);
  return $ex[1];
}

$baseUrl = file_get_contents('http://myserverip/get-listing.php');

$domdoc = new DOMDocument();
$domdoc->strictErrorChecking = false;
$domdoc->recover=true;
@$domdoc->loadHTML($baseUrl);
$links = $domdoc->getElementsByTagName('a');
$i = 0;
$count = 0;
$streams_url = $xpath->query("//span[@id='streams'"]);
echo $streams_url;

$data = array();
>?

Here is the html data:

<a id="link1" href="http://myserverip/getlisting.php?channel=skyatlantic">http://myserverip/getlisting.php?channel=Sky Atlantic&id=108</a><br><br><a id="streams" href="rtmp://www.testserver.com/skyatlantic">Stream 1</a>

Here is what I want to achieve:

http://www.testserver.com/stream01

I want to parse each element from the streams tags.

Can you please show me how i could do this in PHP??

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_url as $a) {
    $url[] = $a->getAttribute("href");
}
print_r($url); // array of href values