Jump to content

php get meta tags help


MDanz

Recommended Posts

<?php

$tags = get_meta_tags('http://www.realgm.com/');

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

?>

 

i just used any website.. i can't get the meta tags though... what am i doing wrong?  i get these error messages..

 

Warning: get_meta_tags() [function.get-meta-tags]: URL file-access is disabled in the server configuration in /home/ustackc1/public_html/menu.php on line 78

 

Warning: get_meta_tags(http://www.realgm.com/) [function.get-meta-tags]: failed to open stream: no suitable wrapper could be found in /home/ustackc1/public_html/menu.php on line 78

 

 

Link to comment
https://forums.phpfreaks.com/topic/179413-php-get-meta-tags-help/
Share on other sites

I don't know.  But if your server provided has the URL file-access disabled, then you will probably have to use cURL (if that is enabled).  I have never used it, in fact, never even looked at it, so maybe someone else can offer an idea.

 

Sorry,

try this,

I have been a little lazy here with the RegEx's

<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.realgm.com/");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$html = curl_exec($ch);
curl_close($ch);
$meta = array();
preg_match_all('/<meta[^>]*?name\s*=\s*(["\'])([^\1>]*?)\1[^>]*?content\s*=\s*(["\'])([^\3>]*?)\3/sim', $html, $result, PREG_SET_ORDER);
foreach($result as $M){
$meta[$M[2]] =$M[4];
}
preg_match_all('/<meta[^>]*?content\s*=\s*(["\'])([^\1>]*?)\1[^>]*?name\s*=\s*(["\'])([^\3>]*?)\3/sim', $html, $result, PREG_SET_ORDER);
foreach($result as $M){
$meta[$M[2]] =$M[4];
}

var_dump($meta);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.