Simplely run following codes to your site by chaning http url.
<?php
// Web page URL
$url = 'https://horje.com';
// Extract HTML using curl
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$data = curl_exec($ch);
curl_close($ch);
// Load HTML to DOM object
$dom = new DOMDocument();
@$dom->loadHTML($data);
// Parse DOM to get Title data
$nodes = $dom->getElementsByTagName('title');
$title = $nodes->item(0)->nodeValue;
// Parse DOM to get meta data
$metas = $dom->getElementsByTagName('meta');
$description = $keywords = '';
for($i=0; $i<$metas->length; $i++){
$meta = $metas->item($i);
if($meta->getAttribute('name') == 'description'){
$description = $meta->getAttribute('content');
}
if($meta->getAttribute('name') == 'keywords'){
$keywords = $meta->getAttribute('content');
}
if($meta->getAttribute('property')=='og:image'){
$meta_og_image = $meta->getAttribute('content');
}
}
$src = preg_match('/<img.+src=[\'"]http(?P<src>.+?)[\'"].*>/i', $data, $result);
$img = 'http'.$result[1].'';
echo "Title: $title". '<br/>';
echo "Description: $description". '<br/>';
echo "Keyword: $keywords". '<br/>';
echo "OG Image: $meta_og_image". '<br/>';
echo "Imgage: $img". '<br/>';
?>
Type: | php |
Category: | Web Tutorial |
Sub Category: | PHP Extract Tutorial |
Uploaded by: | Admin |