Simple approch, get it by curl
<?php
$url = "https://devsach.in/";
function file_get_contents_curl($url){
$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);
return $data;
}
$html = file_get_contents_curl($url);
//parsing begins here:
$doc = new DOMDocument();
@$doc->loadHTML($html);
$nodes = $doc->getElementsByTagName('title');
$title = $nodes->item(0)->nodeValue;
$tags = [];
$metas = $doc->getElementsByTagName('meta');
foreach ($metas as $element) {
$tag = [];
foreach ($element->attributes as $node) {
$tag[$node->name] = $node->value;
}
$tags[] = $tag;
}
print_r($tags);
echo "Title: $title". '<br/><br/>';
This will output
Array
(
[0] => Array
(
[charset] => utf-8
)
[1] => Array
(
[name] => viewport
[content] => width=device-width, initial-scale=1
)
[2] => Array
(
[property] => language
[content] => en
)
[3] => Array
(
[property] => last-modified-date
[http-equiv] => last-modified
[content] => 2021-08-02
)
[4] => Array
(
[property] => og:type
[content] => article
)
[5] => Array
(
[property] => og:site_name
[content] => Sachin :: Welcome to devsach.in
)
[6] => Array
(
[property] => og:url
[content] => https://devsach.in/
)
[7] => Array
(
[property] => og:description
[name] => description
[content] => Hello! I am Web Developer from India, New Delhi. I have rich experience in application development, web site design and development, also I am good at VoIP application development. I love to talk with you about our unique.
)
[8] => Array
(
[property] => og:image
[content] => https://devsach.in/android-icon-192x192.png
)
[9] => Array
(
[name] => twitter:title
[property] => og:title
[content] => Hey there!! welcome to devsach.in
)
[10] => Array
(
[name] => twitter:description
[content] => Hello! I am Web Developer from India, New Delhi. I have rich experience in application development, web site design and development, also I am good at VoIP application development. I love to talk with you about our unique.
)
[11] => Array
(
[name] => twitter:card
[content] => summary
)
)
Title: :: DevSachin