PHP Script To Fetch Title, Keyword and Description Tags


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.

$url = “";
$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 with whatever site you want to pull data from. The results will look like this:

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 thoughts on “PHP Script To Fetch Title, Keyword and Description Tags

  1. 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!


  2. 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

Comments are closed.