Created
November 19, 2015 08:23
-
-
Save joeydenbraven/4951de9ac83b1ccb1cad to your computer and use it in GitHub Desktop.
A way to get meta data from external url via php including opengraph items, so you can use it on your site.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Url | |
$link = 'http://www.google.com'; | |
//Get all meta tags and loop through them | |
if($link!=''){ | |
$sites_html = file_get_contents($link); | |
$html = new DOMDocument(); | |
@$html->loadHTML($sites_html); | |
$meta_og_img = null; | |
foreach($html->getElementsByTagName('meta') as $meta) { | |
if($meta->getAttribute('name')=='title'){ | |
$meta_title = $meta->getAttribute('content'); | |
} | |
if($meta->getAttribute('name')=='author'){ | |
$meta_author = $meta->getAttribute('content'); | |
} | |
if($meta->getAttribute('name')=='description'){ | |
$meta_description = $meta->getAttribute('content'); | |
} | |
if($meta->getAttribute('property')=='og:title'){ | |
$meta_og_title = $meta->getAttribute('content'); | |
} | |
if($meta->getAttribute('property')=='og:site_name'){ | |
$meta_og_sitename = $meta->getAttribute('content'); | |
} | |
if($meta->getAttribute('property')=='og:image'){ | |
$meta_og_img = $meta->getAttribute('content'); | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment