<?php /* Online PHP Examples with Source Code website: http://4evertutorials.blogspot.com/ */ function get_meta_data($url, $searchkey='') { $data = get_meta_tags($url); // get the meta data in an array foreach($data as $key => $value) { if(mb_detect_encoding($value, 'UTF-8, ISO-8859-1', true) != 'ISO-8859-1') { // check whether the content is UTF-8 or ISO-8859-1 $value = utf8_decode($value); // if UTF-8 decode it } $value = strtr($value, get_html_translation_table(HTML_ENTITIES)); // mask the content if($searchkey != '') { // if only one meta tag is in demand e.g. 'description' if($key == $searchkey) { $str = $value; // just return the value } } else { // all meta tags $pattern = '/ |,/i'; // ' ' or ',' $array = preg_split($pattern, $value, -1, PREG_SPLIT_NO_EMPTY); // split it in an array, so we have the count of words $str .= '' . $key . ' (' . count($array) . ' words | ' . strlen($value) . ' chars)' . $value . '
'; // format data with count of words and chars } } return $str; } ?>
<?php /* Online PHP Examples with Source Code website: http://4evertutorials.blogspot.com/ */ $content = get_meta_data("http://4evertutorials.blogspot.com/"); echo ""; print_r($content); echo ""; ?>
0 comments:
Post a Comment