user2784408
user2784408

Reputation: 37

Getting META tag Attributes PHP From URL

Hi i am having an issue when scraping meta tags from a url, the code works on php fiddle but on my server it will return data from what appears to be a different file, a number of the tag properties are different. For example the 'og:url' meta tag returns the tld (domain) only without the path passed. In the browser and phpfiddle the same code returns the full url, including the path as desired. It appears to be treating the request from the server differently. Any ideas would be much appreciated.

$dom = new DOMDocument();
@$dom->loadHTMLFile($url);

foreach( $dom->getElementsByTagName('meta') as $meta ) { 
    echo $meta->getAttribute('property'). "=>" .$meta->getAttribute('content').";\n";
}

Upvotes: 0

Views: 218

Answers (1)

FileX
FileX

Reputation: 11

Try http://php.net/manual/de/function.get-meta-tags.php May it works. Should work with curl too, but I havent enough experience with curl. I hope I could help you.

Upvotes: 1

Related Questions