1- Php built-in function (get_meta_tags).
Note:
Only meta tags with name attributes will be parsed. Quotes are not required.
<?php
// in my case i want to get 4 meta tags. you can get tag which you want.
$tags = get_meta_tags('https://shorttutorial007.blogspot.com/'); // pass the url
// it will return all meta tags in array now you can get the value of meta tags which you want.
echo $tags['author'];
echo $tags['keywords'];
echo $tags['description'];
echo $tags['generator'];
?>
Returns Values
Returns an array with all the parsed meta tags.
The value of the name property becomes the key, the value of the content property becomes the value of the returned array, so you can easily use standard array functions to traverse it or access single values. Special characters in the value of the name property are substituted with '_', the rest is converted to lower case. If two meta tags have the same name, only the last one is returned.
Dom parser travels based on tree based and before access the data, it will load the data into dom object and it will update the data to the web browser.
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('https://shorttutorial007.blogspot.com/');
// PHP parsing begins here:
$doc = new DOMDocument();
@$doc->loadHTML($html);
$nodes = $doc->getElementsByTagName('title');
//get and display what you need:
$title = $nodes->item(0)->nodeValue; // get title
$metas = $doc->getElementsByTagName('meta');
for ($i = 0; $i < $metas->length; $i++)
{
$meta = $metas->item($i);
if($meta->getAttribute('name') == 'description'){ //check attribute name
$description = $meta->getAttribute('content'); // get description
}
if($meta->getAttribute('name') == 'keywords'){ //check attribute name
$keywords = $meta->getAttribute('content'); // get keywords
}
}
echo "Title: $title". '<br/><br/>';
echo "Description: $description". '<br/><br/>';
echo "Keywords: $keywords";
Yeah! You have learned ЁЯШК
I hope you understood this and like this article. if you like it so, please give feedback in the comment section.If any mistakes I made here, so please let me know and improve me.If you have any query, feel free to ask me ЁЯШК
Recommended post
- How to Get All Google play store apps List using PHP Scraper?
- How to pass a variable from the command line using PHP?
- How to Submit Registration and Login Form in PHP?
- Introduction PHP
- how to declare variables in PHP?
- What things you need to install PHP?
- How to get meta tags in 2 easy way in PHP
- How to Encode and Decode Strings with Base64 in JavaScript examples
- How to Reset DropDownList Selection Using jQuery?
- Create dynamic drop-down list option with JavaScript and jQuery
- Onclick show and hide div using JQuery with examples
Post a Comment
Please do not enter any spam link in the comment section.