title: Problems on getting a page's title with PHP
body: <p>I did this function in PHP to get a page's title. I know it might look a bit messy, but that's because I'm a beginner in PHP. I have used <code>preg_match("/&lt;title&gt;(.+)&lt;\/title&gt;/i",$returned_content,$m)</code> inside the if before and it hasn't worked as I expected.</p>
  
  <pre><code>function get_page_title($url) {
      $returned_content = get_url_contents($url);
      $returned_content = str_replace("\n", "", $returned_content);
      $returned_content = str_replace("\r", "", $returned_content);
      $lower_rc = strtolower($returned_content);
      $pos1 = strpos($lower_rc, "&lt;title&gt;") + strlen("&lt;title&gt;");
      $pos2 = strpos($lower_rc, "&lt;/title&gt;");
      if ($pos2 &gt; $pos1)
          return substr($returned_content, $pos1, $pos2-$pos1);
      else
          return $url;
  }
  </code></pre>
  
  <p>This is what I get when I try to get the titles of the following pages using the function above:
  <a href="http://www.google.com" rel="nofollow">http://www.google.com</a> -> "302 Moved"
  <a href="http://www.facebook.com" rel="nofollow">http://www.facebook.com</a> -> ""http://www.facebook.com"
  <a href="http://www.revistabula.com/posts/listas/100-links-para-clicar-antes-de-morrer" rel="nofollow">http://www.revistabula.com/posts/listas/100-links-para-clicar-antes-de-morrer</a> -> "http://www.revistabula.com/posts/listas/100-links-para-clicar-antes-de-morrer"
  (When I add a / to the end of the link, I can get the title successfully: "100 links para clicar antes de morrer | Revista Bula")</p>
  
  <p><strong>My questions are:</strong>
  - I know google is redirecting to my country's mirror when i try to access google.com, but how can I get the title of the page it redirects to?
  - What is wrong in my function that makes it get the title of some pages, but not of others?</p>