Extract meta tags from a website
By: Daniel

Have you ever wanted to get the meta tags from any website in an easy to manage way? There is a built in PHP function called get_meta_tags. This extracts all meta tags from the website and places them in an array. This array contains the tag name as the key, then the value is the data for the meta tag.

<?php
echo '<pre>'; // Make the tags easier to read with <pre>
// Get meta information of "http://www.wlscripting.com"
$metaTags = get_meta_tags('http://www.wlscripting.com');

// Print the array
print_r($metaTags);
echo '</pre>';
?>

This would produce an output of:

Array
(
    [keywords] => wlscripting, white lake scripting, whitelake, scripting, php, classes, code, counters, mysql, data validation, csv, free
    [description] => PHP Tutorials
    [author] => Daniel Kassner
    [robots] => ALL
)

You can then easily loop through the $metaTag variable to do anything you wished with the data.

**Note: You may also use the path to a file instead of a web address to achieve the same results.

1 Star2 Stars3 Stars4 Stars5 Stars (4 votes, average: 4.50 out of 5)
Loading ... Loading ...

Leave a Reply

geovisitors