title: How can I use "PHP Simple HTML DOM Parser" to get the contents of an <h1></h1> tag?
body: <p>I'm new to PHP =) Right now I am using PHP includes for my site template. I have my header, containing all my <code>&lt;head&gt;&lt;/head&gt;</code> info. What I want to do is write a code that will take the contents of the <code>&lt;h1&gt;&lt;/h1&gt;</code> tag from the page, and echo it into the <code>&lt;title&gt;&lt;/title&gt;</code> tag in my header.php include.</p>
  
  <p>I got the PHP Simple HTML DOM Parser from here: [<a href="http://simplehtmldom.sourceforge.net/][1]" rel="nofollow noreferrer">http://simplehtmldom.sourceforge.net/][1]</a>, and I found a code (I forget where in all my googling) that goes like this:</p>
  
  <pre><code>&lt;?php
  $url = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
  $html = file_get_html('http://www.myurl.com/');
  foreach($html-&gt;find('#content h1') as $element){
      echo $element-&gt;plaintext;}
  ?&gt;
  </code></pre>
  
  <p>That I think is supposed to echo the h1 tag contents? Like I said, I'm new to PHP and I only know the basics, and I don't know really know any OOP (yet), so I'm sorry if I'm asking a dumb question.</p>
  
  <p>It looks like it's getting the current page, then putting the contents of the h1 tag into the variable $element, and then echoing it. But nothing happens when I put it into my page. Can anyone help me with what I'm doing wrong? Thank you for reading!! =)</p>
  
  <p>EDIT: Here's my HTML</p>
  
  <p>From the header.php file:</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
  
  &lt;?php
  /* current page url */
  function curPageURL() {
   $pageURL = 'http';
   if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
   $pageURL .= "://";
   if ($_SERVER["SERVER_PORT"] != "80") {
    $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
   } else {
    $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
   }
   return $pageURL;
  }
  ?&gt;
  
  &lt;?php include '/home/dreami14/public_html/simplehtmldom/simplehtmldom/simple_html_dom.php' ?&gt;
  
  &lt;title&gt;
  &lt;?php
  $url = curPageURL();
  $html = file_get_html($url);
  foreach($html-&gt;find('#main h1') as $element){
      echo $element-&gt;plaintext;}
  ?&gt;&lt;/title&gt;
  
  &lt;link rel="stylesheet" type="text/css" href="/stylesheet.css" /&gt;
  &lt;/head&gt;
  &lt;body&gt;
  </code></pre>
  
  <p>From test.php:</p>
  
  <pre><code>&lt;?php include '/home/dreami14/public_html/design/includes/head.php' ?&gt;
  
  &lt;div id="main"&gt;
  &lt;h1&gt;This should be the title&lt;/h1&gt;
  &lt;p&gt;Blah blah&lt;/p&gt;
  &lt;/div&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I don't get any errors, but my <code>&lt;title&gt;&lt;/title&gt;</code> is empty.</p>
  
  <p>Edit to add: also, I echoed $url in the document itself so I know that part is working</p>