Horje

How to extract title description og image keyword other image from URL

Simplely run following codes to your site by chaning http url.

index.html
Example: PHP
<?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/>'; 

 
?>

Output should be:

How to extract title description og image keyword other image from URL



Single Articles
How to extract title description og image keyword other image from URLPHP Extract Tutorial


Related Articles
How to extract Domain Name from Full URL in PHP PHP Extract Tutorial
How to extract only name from domain in PHP PHP Extract Tutorial
How to extract All url from a single page by PHP PHP Extract Tutorial
How to get first Five Line from CSV File PHP Extract Tutorial
How to get first 100 records from a csv file in PHP PHP Extract Tutorial
How to get meta Tag PHP Extract Tutorial
How to get title description image and multiple images from URL PHP Extract Tutorial
How to read a txt file from a zip remote URL PHP Extract Tutorial
How to extract all url from a html single page in PHP PHP Extract Tutorial

Type:
Php
Category:
Web Tutorial
Sub Category:
PHP Extract Tutorial
Uploaded by:
Admin