title: Call to a member function getElementsByTagName() on a non-object, why?
body: <p>I wrote this code:</p>
  
  <pre><code>function GetIds($forum_id,$from_page,$to_page) {
  $ids = array();
  $dom = new DOMDocument();
  libxml_use_internal_errors(true);
  for($i = $from_page; $i &lt;= $to_page; $i++){
      $dom-&gt;loadHTMLFile('http://www.example.com/forumdisplay.php?page='.$i.'&amp;f='.$forum_id);
          //$xpath = new DOMXPath($dom);
          //$items = $xpath-&gt;query('//ul[@id="threads"]/li[@id]');
      $items = $dom-&gt;getElementById('threads')-&gt;getElementsByTagName('li');
      foreach($items as $thread) {
      if(($id = substr($thread-&gt;getAttribute('id'), 7)) !== false)
      $ids[] = $id;
      }
  }
      return $ids;
  }
  </code></pre>
  
  <p>To get all the threads Ids from this forum, example of use:</p>
  
  <pre><code>$tids = GetIds("67",1,2); //Get all the Ids from page 1 to 2.
  foreach($tids as $data) {
  $file = fopen("threads.txt", "a+");
  fwrite($file, "{$data}:");
  fclose($file);
  }
  </code></pre>
  
  <p>When i run the code i get this error:
  <strong>Call to a member function getElementsByTagName() on a non-object in C:\wamp\www\eProject\functions.PHP on line 145</strong></p>
  
  <p>line 145:</p>
  
  <pre><code>$items = $dom-&gt;getElementById('threads')-&gt;getElementsByTagName('li');
  </code></pre>
  
  <p>What is the problem?</p>