Fetch Meta Data from URL using PHP and Ajax

In this tutorial am going to explain how to get meta data from an URL to display in website. It’s similar to URL data extracting. You can see this example most of social networking sites like Facebook and Google Plus. It also called as Extracting data from URL using Jquery, Ajax and PHP.

Fetch Meta Data form URL using PHP and Ajax

Download FileDemo

I have used get_meta_tags PHP function to get the Meta data from URL. This is a PHP in built function. The output will be returned in array.

$url=get_meta_tags("http://www.webinfopedia.com/"); 

This will give you an array of all Meta data like Description, Keyword, Author, Copyright, Robot etc… Now you need to display it like below.

echo ($url["description"]);
echo substr($url["keywords"], 0, 128); 
echo ($url["copyright"]);

To get the title tag form URL am using file_get_contents function.

echo get(file_get_contents('http://www.webinfopedia.com/'), "");
//get function 
function get($a,$b,$c)
{
 // Gets a string between 2 strings
$y = explode($b,$a);
$x = explode($c,$y[1]);
return $x[0];
}

Using same this method you can also fetch the first image from URL. Check the function below:

echo get(file_get_contents(''.$_REQUEST['url'].''), "");

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>