Jump to content

mark107

Members
  • Posts

    113
  • Joined

  • Last visited

Everything posted by mark107

  1. You heard me. Yes of course I do, I want to fetch the elements from the ID "Streams" for each channel. I have got two different href value which there are <a id="link1" and <a id="streams". Each channel I have as it have got the same ID "Streams" but it come with each different link, example: rtmp://www.testserver.com/bbc1, rtmp://www.testserver.com/bbc2...etc. When I try this: $streams_url = $domdoc->getElementsByTagName('a'); foreach($streams_url as $a) { $url[0] = $a->getAttribute("href"); print_r($url); } I will get the full elements from the both html tags <a id="link1" and <a id="streams". Here is the output: Array ( [0] => http://myserverip/get-listing.php?channels=BBC One S East&id=101 ) Array ( [0] => rtmp://www.testserver.com/bbc1 ) Array ( [0] => http://myserverip/get-listing.php?channels=BBC Two&id=102) Array ( [0] => rtmp://www.testserver.com/bbc2 ) Array ( [0] => http://myserverip/get-listing.php?channels=ITV&id=103 ) Array ( [0] => rtmp://www.testserver.com/itv1 ) Array ( [0] => http://myserverip/get-listing.php?channels=Channel 4&id=104 ) Array ( [0] => rtmp://www.testserver.com/channel4 ) Array ( [0] => http://myserverip/get-listing.php?channels=Channel 5&id=105 ) Array ( [0] => rtmp://www.testserver.com/channel5 ) Array ( [0] => http://myserverip/get-listing.php?channels=Sky One&id=106 ) Array ( [0] => rtmp://www.testserver.com/skyone ) Array ( [0] => http://myserverip/get-listing.php?channels=Sky Living&id=107 ) Array ( [0] => rtmp://www.testserver.com/skyliving ) Array ( [0] => http://myserverip/get-listing.php?channels=Sky Atlantic&id=108 ) Array ( [0] => rtmp://www.testserver.com/skyatlantic ) Here is the full code: <?php ini_set('max_execution_time', 300); //error_reporting(0); $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); $streams_url = $domdoc->getElementsByTagName('a'); foreach($streams_url as $a) { $url[0] = $a->getAttribute("href"); print_r($url); } ?> What I want to achieve is I want to get the elements from the ID "Streams" tags to make it show like this: Array ( [0] => rtmp://www.testserver.com/bbc1 ) Array ( [0] => rtmp://www.testserver.com/bbc2 ) Array ( [0] => rtmp://www.testserver.com/itv1 ) Array ( [0] => rtmp://www.testserver.com/channel4 ) Array ( [0] => rtmp://www.testserver.com/channel5 ) Array ( [0] => rtmp://www.testserver.com/skyone ) Array ( [0] => rtmp://www.testserver.com/skyliving ) Array ( [0] => rtmp://www.testserver.com/skyatlantic ) Do you know what is the best way I could use to parse the elements from the tag from the ID "Streams" while ignore the elements from the other tag??
  2. Yes I have fixed the issues and I have forgot to add the xpath to definte it. I want to parse the element from one of these hyperlink. Here there are two different hyperlinks: <a id="link1" href="http://myserverip/getlisting.php?channel=skyatlantic">http://myserverip/getlisting.php?channel=Sky Atlantic&id=108</a> <a id="streams" href="rtmp://www.testserver.com/skyatlantic">Stream 1</a> I want to parse the element from the tag called "streams". When I try this: $xpath = new DOMXpath($domdoc); $el = $domdoc->getElementById('streams'); $url = $el->getAttribute('href'); //$streams_url = $xpath->query('//[@id="streams"]'); echo $url; It will only let me to parse one of these element as I have got more than one element in my html code. Do you know how i could parse each element from each streams tags??
  3. Sorry I have make a mistake with my code. I can see there is no span tag as I am using the <a id tags so do you know how I could parse the <a id tag to get the element from the href?? Here is where you can see it: <a id="streams" href="rtmp://www.testserver.com/skyatlantic">Stream 1</a>
  4. Hi guys, 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'"]); echo $streams_url; 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(); foreach($links as $link) { if($link->getAttribute('href')) { } } >? 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: rtmp://www.testserver.com/skyatlantic I want to parse each element from the streams tags. Can you please show me how i could do this in PHP??
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.