[PHP] Function get_meta_tags() Helper
2018-02-21 / Dimas Lanjaka Kumala Indra
Description Of get_meta_tags
Source Description: PHP.NET(PHP 4, PHP 5, PHP 7)
get_meta_tags — Extracts all meta tag content attributes from a file and returns an array
This function helper needs cURL or file_get_contents()
Click Here To Find Function Helper For file_get_contents() on PHP
Function helper for get_meta_tags();
function get_meta(val){<br>tags = get_meta_tags($val);
return array(‘author’ => $tags[‘author’], ‘description’ => $tags[‘description’], ‘keywords’ => tags['keywords']);<br>}<br><br>function get_metas(url){
url); //Define your cURL functions
//parsing begins here:
doc->loadHTML(nodes = doc->getElementsByTagName('title');<br>//get and display what you need:<br>title = nodes->item(0)->nodeValue; //titles<br>metas = doc->getElementsByTagName('meta');<br>for (i = 0; $i < $metas->length; $i++)
{
$meta = metas->item(i);
if($meta->getAttribute(‘name’) == ‘author’){
$author = meta->getAttribute('content');<br> }<br> if(meta->getAttribute(‘name’) == ‘description’){
$description = meta->getAttribute('content');<br> }<br> if(meta->getAttribute(‘name’) == ‘keywords’){
$keywords = $meta->getAttribute(‘content’);
}
}
return array(‘description’ => $description, ‘author’ => $author, ‘keywords’ => keywords);<br>}<br></pre><h2 class="w3-center">Usage Function Helper For</h2><pre><br>targeturl = “https://web-manajemen.blogspot.com”; //target url to scraped
if (get_meta_tags(targeturl) == FALSE){<br>meta = get_metas(targeturl);<br>} else {<br>meta = get_meta(targeturl);<br>}<br><br>getDesc = getKey = getAuthor = meta['author'];<br><br>echo "<b>Description: </b>".getDesc."<hr />";
echo “<b>Keywords: </b>”.getKey."<hr />";<br>echo "<b>Author: </b>".getAuthor."<hr />";
[PHP] Function get_meta_tags() Helper
PermaLink: https://www.webmanajemen.com/2018/02/php-function-getmetatags-helper.html
Google Rich Snippets | Schema Markup Validator | Google Pagespeed Insight