Jump to content

how to get list of arrays using domdocument?


mark107

Recommended Posts

I have the list of tags in php and I want to get the contents.

 

for example:

 


    <li class="zc-ssl-pg" id="row0-1" style="">
    <span id="row1Time" class="zc-ssl-pg-time">6:00 PM</span>
    <a id="rowTitle1" class="zc-ssl-pg-title" href='http://www.mysite.com'>Melissa & Joey</a>
    <a class="zc-ssl-pg-ep" href='http://www.mysite.com'>"House Broken"</a>
    
    <li class="zc-ssl-pg" id="row1-1" style="">
    <span id="row1Time" class="zc-ssl-pg-time">6:00 PM</span>
    <a id="rowTitle1" class="zc-ssl-pg-title" href='http://www.mysite.com'>The Middle</a>
    <a class="zc-ssl-pg-ep" href='http://www.mysite.com'>"Thanksgiving IV"</a>

 

 

Here's the PHP:

 


    <?php
    $errmsg_arr = array();
    $errflag = false;
    $link;
    
    function db_connect()
    {
      define('DB_HOST', 'localhost');
      define('DB_USER', 'myusername');
      define('DB_PASSWORD', 'mypassword');
      define('DB_DATABASE', 'mydbname');
   
      $errmsg_arr = array();
      $errflag = false;
      $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
    
      if(!$link) 
      {
        die('Failed to connect to server: ' . mysql_error());
      }
    
      $db = mysql_select_db(DB_DATABASE);
      if(!$db) 
      {
        die("Unable to select database");
      }
    }
    db_connect();
    
    $qrytable1="SELECT id, channels, links, streams FROM tvguide";
    $result1=mysql_query($qrytable1) or die('Error:<br />' . $qry . '<br />' . mysql_error());
          
          
      $links = "WEBSITE URL";
      $result = file_get_contents($links);
      $dom = new DOMDocument();
      $dom->loadHTML($result);
      echo $dom->getElementById('row1Time')->nodeValue . "<br>";
    ?>

 

 

When I use the code as above, it will only get the contents from the tags with array value 0.

 

I want to get the tags `row1Time, rowTitle1 and zc-ssl-pg-ep with the array 1 value. 

 

Can you please tell me how I can get the contents from the class tags with the array value 1 using with DOMDocument? 

Link to comment
Share on other sites

FYI in HTML an id is supposed to be unique. That means not using it multiple times like you're currently doing with id="row1Time".

 

Use getElementsByTagName() to get all the spans, then loop over that and grab every one with the right id (or class).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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