I was going to suggest get_meta_tags () , but it doesn't seem to work (for me): s
<?php
$tags = get_meta_tags('http://www.example.com/');
echo $tags['og:image'];
?>
But I would prefer to use DOMDocument anyway:
<?php
$sites_html = file_get_contents('http://example.com');
$html = new DOMDocument();
@$html->loadHTML($sites_html);
$meta_og_img = null;
foreach($html->getElementsByTagName('meta') as $meta) {
if($meta->getAttribute('property')=='og:image'){
$meta_og_img = $meta->getAttribute('content');
}
}
echo $meta_og_img;
?>
Hope this helps
source
share