Remote Meta Tag and Title Script

Posted By: Ian on Feb 26, 2014 in PHP, Snippets
Last modified on January 29th, 2015 at 9:31 pm,

Today i share the basics of MetaTagGrabber.com (Which i own) which is a script for extracting the following from a remote webpage: –

  • Title
  • Description
  • Keywords
  • Author
  • Copyright
  • Email

Using fopen is only good if it’s enabled in your php.ini else you should probably use CURL

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Remote Meta Tag and Title Retrieval</title>
<style type="text/css">
.db-table {
border-bottom : 0.063em solid #ccc;
border-right : 0.063em solid #ccc;
margin : 0 auto;
text-align : left;
background : #fff;
}
.db-table th {
background : #E8E8E8;
border-left : 0.063em solid #ccc;
border-top : 0.063em solid #ccc;
padding : 0.313em;
}
.db-table td {
border-left : 0.063em solid #ccc;
border-top : 0.063em solid #ccc;
padding : 0.313em;
}
</style>
</head>
<body>
<?php
$uri = "http://metataggrabber.com";
//a function to check whether the url exists or not and validate it
function check_url($uri)
{
$check = @fopen($uri, "r"); // we are opening url with fopen
if ($check)
$status = true;
else
$status = false;
return $status;
}
if (check_url($uri)) {
$check = @fopen($uri, "r"); // we are opening url with fopen
$text = @fread($check, 16384);
if (preg_match('/<title>(.*?)</title>/is', $text, $found)) {
$title = $found[1];
} else {
$title = " <-- No title found --> ";
}
$tags = get_meta_tags($uri);
$description = (!empty($tags['description']) ? $tags['description'] : 'No description tag found');
$keywords = (!empty($tags['keywords']) ? $tags['keywords'] : 'No keywords tag found');
$author = (!empty($tags['author']) ? $tags['author'] : 'No author tag found');
$copyright = (!empty($tags['copyright']) ? $tags['copyright'] : 'No copyright tag found');
$email = (!empty($tags['email']) ? '<a href="mailto:' . $tags['email'] . '" title="email webmaster">' . $tags['email'] . '</a>' : 'No email tag found');
$message = <<<OUTPUT
<table cellpadding="0" cellspacing="0" class="db-table">
<caption>Results for: <a href="$uri">$uri</a></caption>
<tbody>
<tr>
<th>Page Title</th>
<td>$title</td>
</tr>
<tr>
<th>Description</th>
<td>$description</td>
</tr>
<tr>
<th>Keywords</th>
<td>$keywords</td>
</tr>
<tr>
<th>Author</th>
<td>$author</td>
</tr>
<tr>
<th>Copyright</th>
<td>$copyright</td>
</tr>
<tr>
<th>Email</th>
<td>$email</td>
</tr>
</tbody>
</table>
OUTPUT;
}
if (!empty($message)) {
echo $message;
}
?>
</body>
</html>


Try MeDownload

AnonymousIan.J.Gough

Did this help you? Please Let me know by commenting below even if it’s just to say “Thanks”

leave a comment

About This Site

Dreams are built from lines of code well it's true!
If you can dream it you can usually code it.

I have learned so much from other people on the Internet and this site is for me to give back some of what i have learned and hope people can now learn from me.
Have fun and surf safely,
Ian.J.Gough

protected by copyscape duplicate content check

Categories


Powered by Banner Bar 125