Someone recently asked for a way to quickly pull basic page info from a website, so I thought I’d go ahead and share the code for a very easy PHP script that will retrieve the page title, meta keywords and meta description for any website.
<?php
$url = “http://www.shamwow.com";
$fp = fopen( $url, ‘r’ );
$content = “”;
while( !feof( $fp ) ) {
$buffer = trim( fgets( $fp, 4096 ) );
$content .= $buffer;
}
$start = ‘<title>’;
$end = ‘<\/title>’;
preg_match( “/$start(.*)$end/s”, $content, $match );
$title = $match[ 1 ];
$metatagarray = get_meta_tags( $url );
$keywords = $metatagarray[ "keywords" ];
$description = $metatagarray[ "description" ];
echo “<div><strong>URL:</strong> $url</div>\n”;
echo “<div><strong>Title:</strong> $title</div>\n”;
echo “<div><strong>Description:</strong> $description</div>\n”;
echo “<div><strong>Keywords:</strong> $keywords</div>\n”;
?>
There’s your basic script. Replace where it says www.shamwow.com with whatever site you want to pull data from. The results will look like this:
URL: http://www.shamwow.com
Title: ShamWow® Official Website – Holds 12 Times Its Weight In Liquid
Description: You’ll Be Saying Wow Every Time!
Keywords:You’ll Be Saying Wow Every Time!, official tv website, as seen on tv
Where to go from here? There are millions of different uses from SERP reporting to page title & keyword comparison. Heck, you could even throw a form on it and present it as an SEO tool on your website (almost every ‘toolset’ you find online has something similar)….

7 ResponsesLeave a comment ?
Good works!
Great`s!
This is quite very interesting codes… I would try a bit of it.
hmm good article. thank you for the post. It works.
great work! just a hint:
take care of the timeout for fopen! do not use in production, or eg. immediate after posting your content… etc. let the cms read and parse the urls in a separate process and do caching!
v.
I truly agree with you about this issue. Nice article. Already bookmarked for future reference.
This is informative article. Thank you very much for the great post provided! I was looking for this entry for quite some time, but I wasn