my code is
function getTitle($Url){
$str = file_get_contents($Url);
if(strlen($str)>0){
preg_match("/\<title\>(.*)\<\/title\>/",$str,$title);
return $title[1];
}
else
{
return false;
}
}
function getMetas($Url){
$str = file_get_contents($Url);
if(strlen($str)>0){
// preg_match("/\<title\>(.*)\<\/title\>/",$str,$title);
preg_match("/<meta name=\"description\" content=\"(.*?)\"/",$str,$title);
// preg_match( '<meta name="description".*content="([^"]+)">siU', $str, $title);
return $title[1];
}
else
{
return false;
}
}
//Example:
$url=$_POST['url'];
echo getTitle($url);
echo "<br><br>";
echo getMetas($url);
this does not shows result for all the url's , example http://google.com
I know the question is 1.5 years old. But if you are still looking for it, you can use https://urlmeta.org. Its a free API to extract URL meta.
You can check a URL for http or https by
then you can use the above answer
Why are you using regular expression for parsing the
<meta>
tags ?PHP has an in-built function for parsing the meta information , it is called the
get_meta_tags()
Illustration :
OUTPUT:
As you can see the title , image and description are being parsed which you really want.