How to get all META data of a website.

How to get all META data of a website.

In this tutorial I will show you how you can easy check META information of any website. It can be very usefull in search engine optimization when you want to check your competitors settings.

Step 1.

To get meta information you need to connect to the actual domain and get the webserver output, which is a html page. After it you can analyse it looking for mate tags. However it seems this function was quite often requested so PHP has a built in realistion of this issue sinc PHP 3. So all you need to know to call the PHP built in function get_meta_tags(). This function extracts all meta tag content attributes from a file and returns an array. After we have this array just look whether it contains any element or not and list them as you want.

So let's create a function which has one input parameter - the requested domain. The function uses the get_meta_data() function and next checks the array size. If the array is empty than displays a message that no Meat information was found. Otherwise the function go through the array and displays each element as a key - value pair.

The code looks like this:


 * Function to read meta information from the given domain.
 * @param string $domain
function getSiteMeta($domain){
// Read META info
$tags = get_meta_tags($domain);

// Check the result and display it.
if (sizeof($tags) == 0){
'<tr><td>No META information was found!</td></tr>';
  foreach (
$tags as $key=>$value) {
"<tr><td>$key: </td><td>$value</td></tr>";



Step 2.

It is not so attractive to just create a function, it is much better to make some usable environment for it. To do this we will create web page with a HTML form and during the form processing we will display the meta informations. Although this step is quite simple I will give you a small introduction.
So let's create a simple form with one input box and a submit button. Set the form action to call the script itself so we can do everything in this small php file. During the form processing we need to check the domain name defined by the visitor and make some validation. In this example I only check whether the protocol was defined or not. In any case the script will result the domain without the protocoll part and will be converted to lowercase.  As next step the script echos a table header than calls  the above written function which prints the necessary table rows. At the end closes the table. That's all.

The HTML part of the code is the following: 

   <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="domain">
       <tr><td>Site URL: <input name="domainname" type="text"/></td></tr>
       <tr><td><input type="submit" name="submitBtn" value="Get META" /></td></tr>
if (isset($_POST['submitBtn'])){

$domainbase = isset($_POST['domainname']) ? $_POST['domainname'] : '' ;
$domainbase = str_replace("http://","",strtolower($domainbase));

'<table width="100%">';

You can download a complete META spider as well.