-1

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)

3
  • 2
    Try a print_r($tags); to begin with. Mar 14, 2011 at 8:38
  • i used it... no result just the echo statements.
    – user434885
    Mar 14, 2011 at 9:16
  • See if you get any data at all from remote hosts by using file_get_contents('yahoo.com'); Perhaps you have some kind of firewall. Mar 14, 2011 at 10:58

3 Answers 3

1

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

8
  • there is even an easiest way to check if curl is enabled. In the same file, replace phpinfo() with var_dump(curl_version()). If there will be some errors, it means that you don't have it enabled :)
    – mbajur
    Mar 14, 2011 at 8:54
  • curl was not enabled, so i enabled it but still no result, i also tried print_r($tags); but still no result :/
    – user434885
    Mar 14, 2011 at 9:15
  • please add a error_reporting(E_ALL); line at the beginning of your file (just after <?php) and check if there are no errors
    – mbajur
    Mar 14, 2011 at 9:18
  • oh, and have you restarted apache?
    – mbajur
    Mar 14, 2011 at 9:20
  • ive done all of that, ive changed the code a bit $tags is getting set and its size is greater than 0 but no output :(
    – user434885
    Mar 14, 2011 at 9:29
0

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]);
}
0
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.