Publishing System Settings Logout Login Register
Extracting Meta Tags from a Web Page
TutorialCommentsThe AuthorReport Tutorial
Tutorial Avatar
Rating
Add to Favorites
Posted on November 25th, 2006
3420 views
PHP Coding
Meta Tags? - WTF are those?

Meta Tags are information placed on web pages that provide a summary or description of the content present on that page.  It can contain a lot of information, author of the page, keywords, the works!  They are usually read by search engines such as the Google Bot and soon to come, the SeekBot.  If you view the page of a website, placed in between the <head> tags would be meta information.

The Run Down

There is a handy function already embedded into the PHP library called geT_meta_tags();

With this function, we are able to extract all the meta tag information from any web page or file.  The returned data will be stored into an array, where the name of the meta tag will become the key of the array, and the value of that meta tag will become the value.

The Snippet

[code=PHP]<?php

// Enable pre formatting
echo '<pre>';

// Get meta information of "http://www.pixel2life.com"
$meta = get_meta_tags ( 'http://www.pixel2life.com' );

// Print the array
print_r ( $meta );

?>[/code]

You can also grab meta tags from local files as well.  For example: /home/jamie/public_html/index.html

Results
When that code is ran on the url, our example being Pixel2Life, you would get an output similar to the following:
Array
(
    [author] => Pixel2life.com
    [copyright] => Content Copyright Pixel2life.com. All rights reserved.
    [keywords] => Photoshop Tutorials, Tutorial Index, Tutorials, Tutorial Search Engine, Flash, Macromedia, Adobe, Photoshop, Corel, Coreldraw, Photopaint, HTML Tips and Tricks, PHP Coding, ASP, SQL, Free Image Hosting, Forums, Help, Search, Free Tutorials, Free Hosting, Services, Sig Files, 3d Studio Max
    [description] => Pixel2life is the largest tutorial search engine on the internet catering to graphic designers and programmers.  From Photoshop to Poser to C++, we have it all in the fastest and friendliest search tool around.
)


A closer look
Looking at the source of the web page, you can see that the meta information is in fact correct, presented below:
<meta name="author" content="Pixel2life.com" />
<meta name="copyright" content="Content Copyright Pixel2life.com. All rights reserved." />
<meta name="keywords" content="Photoshop Tutorials, Tutorial Index, Tutorials, Tutorial Search Engine, Flash, Macromedia, Adobe, Photoshop, Corel, Coreldraw, Photopaint, HTML Tips and Tricks, PHP Coding, ASP, SQL, Free Image Hosting, Forums, Help, Search, Free Tutorials, Free Hosting, Services, Sig Files, 3d Studio Max" />
<meta name="description" content="Pixel2life is the largest tutorial search engine on the internet catering to graphic designers and programmers.  From Photoshop to Poser to C++, we have it all in the fastest and friendliest search tool around." />


The utility of this function may not be at the maximum, but websites that provide SEO tools will generally have meta extractors, in which you can dig up the meta tags of a webpage without getting your hands dirty.
Dig this tutorial?
Thank the author by sending him a few P2L credits!

Send
Chaos King

Experienced Web Developer and a Senior Developer at Pixel2Life.com. Being a role model to many future web developers, its what I do best. I enjoy long walks on the beach and arguing with Faken about life.
View Full Profile Add as Friend Send PM
Pixel2Life Home Advanced Search Search Tutorial Index Publish Tutorials Community Forums Web Hosting P2L On Facebook P2L On Twitter P2L Feeds Tutorial Index Publish Tutorials Community Forums Web Hosting P2L On Facebook P2L On Twitter P2L Feeds Pixel2life Homepage Submit a Tutorial Publish a Tutorial Join our Forums P2L Marketplace Advertise on P2L P2L Website Hosting Help and FAQ Topsites Link Exchange P2L RSS Feeds P2L Sitemap Contact Us Privacy Statement Legal P2L Facebook Fanpage Follow us on Twitter P2L Studios Portal P2L Website Hosting Back to Top