PHP - Errors with DOmdocument
<p>Why I am getting the following error </p>

<pre><code> Call to a member function getElementsByTagName() on a non-object
</code></pre>

<p>Error happens on following line:</p>

<pre><code>  $title = $htm-&gt;getElementsByTagName('title');
</code></pre>

<p>when I run the following code:</p>

<pre><code>  $dom = new DOMDocument();

  foreach ($all as $blog) {

    sleep(1);

    $htm = $dom-&gt;loadHTML(fetch_url('http://' . rtrim(preg_replace('/^http:\/\//i', '', $blog['blogurl']), '/')));

    if ($htm) {

      //check TITLE

      $title = $htm-&gt;getElementsByTagName('title');

      $title = $title-&gt;item(0)-&gt;nodeValue;

      if (preg_match('/private/i', $title)) {

        private_blog($blog['id']);

        $title = null;
        unset($title);
        gc_collect_cycles();
        continue;
      }
    }
 }
</code></pre>
