title: php Fatal error: Uncaught ValueError: DOMDocument::loadHTML()
body: <p>I am following a tutorial that shows how to write a program that parses a web page and finds all the links. However, this program works only on pages that use http. Whenever I try to run it against a site that has a certificate (https) it throws the following error:</p>
  <blockquote>
  <p>Fatal error: Uncaught ValueError: DOMDocument::loadHTML(): Argument #1
  ($source) must not be empty in
  C:\xampp\htdocs\froogal\classes\DomDocumentParser.php:14 Stack trace:
  #0 C:\xampp\htdocs\froogal\classes\DomDocumentParser.php(14): DOMDocument-&gt;loadHTML('') #1 C:\xampp\htdocs\froogal\crawl.php(6):
  DomDocumentParser-&gt;__construct('http://www.appl...') #2
  C:\xampp\htdocs\froogal\crawl.php(18):
  followLinks('http://www.appl...') #3 {main} thrown in
  C:\xampp\htdocs\froogal\classes\DomDocumentParser.php on line 14</p>
  </blockquote>
  <p>The code for the DomDocumentParser.php file is:</p>
  <pre><code>&lt;?php
  class DomDocumentParser {
  
      private $doc;
  
      public function __construct($url) {
  
          $options = array(
              'http'=&gt;array('method'=&gt;&quot;GET&quot;, 'header'=&gt;&quot;User-Agent: doodleBot/0.1\n&quot;)
              );
          $context = stream_context_create($options);
  
          $this-&gt;doc = new DomDocument();
          @$this-&gt;doc-&gt;loadHTML(file_get_contents($url, false, $context));
      }
  
      public function getlinks() {
          return $this-&gt;doc-&gt;getElementsByTagName(&quot;a&quot;);
      }
  
  }
  ?&gt;
  </code></pre>
  <p>And the code for crawl.php is:</p>
  <pre><code>&lt;?php
  include(&quot;classes/DomDocumentParser.php&quot;);
  
  function followLinks($url) {
  
      $parser = new DomDocumentParser($url);
  
      $linkList = $parser-&gt;getLinks();
  
      foreach($linkList as $link) {
          $href = $link-&gt;getAttribute(&quot;href&quot;);
          echo $href . &quot;&lt;br&gt;&quot;;
      }
  
  }
  
  $startUrl = &quot;http://www.apple.com&quot;;
  followLinks($startUrl);
  ?&gt;
  </code></pre>