Jump to content

how to ignore the tags?


mark107

Recommended Posts

I need some help with my PHP, I'm to parsing the href contents using DOMDocument.

 

I have the list of url that I'm parsing only for the website link even I want to ignore the `<a id="aTest" href="` tags.

 

Here is the input:

 




http://www.mysite.com/get-listing.php?channels=test 1&id=101
http://www.mysite.com/get-listing.php?channels=test 2&id=102
http://www.mysite.com/get-listing.php?channels=test 3&id=103
rtmp://$OPT:rtmp-raw=rtmp://ny.iguide.to/edge playpath=49f5xnbs2wra0ut swfUrl=http://player.ilive.to/player_ilive_2.swf pageUrl=http://www.ilive.to token=UYDk93k#09sdafjJDHJKAD873



 

 

Here is the output:

 


<a href='http://www.mysite.com/get-listing.php?channels=test 1&id=101'></a></p><a id="aTest" href="">Stream 1</a><br><br>
    <a href='http://www.mysite.com/get-listing.php?channels=test 2&id=102'></a></p><a id="aTest" href="">Stream 1</a><br><br>
    <a href='http://www.mysite.com/get-listing.php?channels=test 3&id=103'></a></p><a id="aTest" href="rtmp://$OPT:rtmp-raw=rtmp://ny.iguide.to/edge playpath=49f5xnbs2wra0ut swfUrl=http://player.ilive.to/player_ilive_2.swf pageUrl=http://www.ilive.to token=UYDk93k#09sdafjJDHJKAD873">Stream 1</a><br><br>

 

 

Here is the PHP:

 



    <?php
    ini_set('max_execution_time', 300);
    $errmsg_arr = array();
    $errflag = false;
    
    $xml .= '<?xml version="1.0" encoding="UTF-8" ?>';
    $xml .= '
    <tv generator-info-name="www.mysite.com/xmltv">';
    
    $baseUrl = file_get_contents('http://www.mysite.com/get-listing.php');
    
    $domdoc = new DOMDocument();
    $domdoc->strictErrorChecking = false;
    $domdoc->recover=true;
    //@$domdoc->loadHTMLFile($baseUrl);
    @$domdoc->loadHTML($baseUrl);
    
    $links = $domdoc->getElementsByTagName('a');
    $data = array();
    foreach($links as $link)
    {
      //echo $domdoc->saveXML($link);
      if($link->getAttribute('href'))
      {
        $url = str_replace(" ", "%20", $link->getAttribute('href'));
        $url = str_replace("rtmp://", "", $link->getAttribute('href'));
      }
    }
    ?>


 

 

Can you please tell me how I can parsing the contents as only for `<a href='http://www.mysite.com/get-listing.php` while ignoring the other contents especially `<a id="aTest" href="`?

 

Does anyone know how?

Link to post
Share on other sites

Note that the following code is untested, but you could try the following:

<?php
if($link->getAttribute('href'))
{
     if(!$link->hasAttribute('id') || $link->getAttribute('id')!='aTest')
     {
          $url = str_replace(" ", "%20", $link->getAttribute('href'));
          $url = str_replace("rtmp://", "", $link->getAttribute('href'));
     }
}
?>
Link to post
Share on other sites

 

Note that the following code is untested, but you could try the following:

<?php
if($link->getAttribute('href'))
{
     if(!$link->hasAttribute('id') || $link->getAttribute('id')!='aTest')
     {
          $url = str_replace(" ", "%20", $link->getAttribute('href'));
          $url = str_replace("rtmp://", "", $link->getAttribute('href'));
     }
}
?>

 

Thank you very much for that, I can see it is working now.

 

Cheers for the help!!!

Link to post
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.