开发者

php getting metadata

i am trying to extract meta data of a website using the following code ive changed my code a little

<?php
error_reporting(E_ALL);
$domain='http://www.yahoo.com';
?>

<h3>Reading the meta-data tags of website: <?php echo $domain; ?></h3>

<?php 

  echo 'Read META info<br>';
  $tags = get_meta_tags($domain);

  echo 'Check the result and display it.<br>';

  if(isset($tags))
      echo 'Tags is set';

  if (sizeof($tags) == 0){
    echo '<tr><td>No META information was found!</td></tr>';
  }
  else
  {
  echo 'Metadata found !!开发者_高级运维';
  print_r($tags);
  }

?>

But im not getting any result. I am running this script of my local WAMP server. Where am i going wrong? just looking to find very basic information about a page.

this is the result im getting "Reading the meta-data tags of website: http://www.yahoo.com Read META info Check the result and display it. Tags is setMetadata found !!"

but no output from the print_r($tags)


for me it works fine. Maybe you don't have curl enabled ? Can you provide us your phpinfo output?

Just create phpinfo.php file with the following code inside:

<?php
phpinfo();
?>

If there will be no word about curl, you need to open your php.ini file, find the ;extension=php_curl.dll line and uncomment it (by removing the ; char)

then restart your apache


It should work just fine, try to debug row-by-row using print_r($tags) . Anyway if it reads well, then you should be able to get for example the keywords like this:

$kws = explode(",",$meta['keywords']);
for ($i=0;$i<count($kws);$i++)
{
    $kws[$i] = ltrim($kws[$i]);
    $kws[$i] = rtrim($kws[$i]);
    echo($kws[$i]);
}


For yahoo.com and google.com you will not get any meta tags. I also tried but i don't know why, may be this sites works as search engine.

<?php
 $tags = get_meta_tags('http://sitename.com/');

 echo $tags['keywords'];    
 echo $tags['description'];  
?>

This code works for other sites in which meta tags are mentioned.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜