Just found out the get_meta_tags() function but i couldn't find a way to fetch a webpage's title other than fetching the whole page and parsing through line by line.
Or am I just missing out on another cool function ?
Fetching the title of a webpage.
There isn't such a function.
Consider looking into regular expressions:
www.php.net/eregi
www.php.net/preg_match
And into string matching:
www.php.net/stristr
www.php.net/strpos
Or into a function I've made to do similar things:
http://www.durdenwebapplications.com/durdenwebapplications_PHP/#StrBetweenStr
This should do what you want using regular expressions.
<?
if ($submit):
$tags = fopen("$data", "r") or die ("Could not open page");
$r = fread($tags, 300);
$r = strtolower($r);
preg_match_all("/<title>.*?\n/", $r, $matches);
$take_out =Array('<', '>', '/', 'title');
$matched =($matches[0][0]);
if(eregi("title", $matched)):
$title = str_replace($take_out, "", $matched);
print"<hr>This is the page title :: <b>$title</b>";
else:
print"<b>Sorry, I could not get the title for this page</b>";
endif;
else:
print"<html><title>Find Title</title>
<body>
<form method=\"POST\" action=\"$PHP_SELF\">
<table width=\"300\" border=\"0\" align=\"center\">
<tr><td>Enter URL !!</td></tr>
<tr><td><input type=\"text\" name=\"data\" value=\"http://www.homestarrunner.com\" size
=\"34\"></td></tr>
<tr><td><input type=\"submit\" name=\"submit\" value=\"Get Title\"></td></tr>
</table>
</form>
</body>
</html>";
endif;
?>