note 87273 modified in function.get-meta-tags by thiago

From: Date: Thu, 27 Nov 2008 12:22:05 +0000
Subject: note 87273 modified in function.get-meta-tags by thiago
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-147031@lists.php.net to get a copy of this message
<?php /* ** Extracts and formats meta tag content */ 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 .= '<p><span style="display:block;color:#000000;font-weight:bold;">' . $key . ' <span style="font-weight:normal;">(' . count($array) . ' words | ' . strlen($value) . ' chars)</span></span>' . $value . '</p>'; // format data with count of words and chars } } return $str; } $content .= get_meta_data("http://www.example.com/"); /* output looks like this: description (23 words | 167 chars) SELFHTML 8.1.2 - Die bekannte Dokumentation zu HTML, JavaScript und CGI/Perl - Tutorial und Referenz, mit etlichen Zusatztips zu Design, Grafik, Projektverwaltung usw. keywords (13 words | 119 chars) SELFHTML, HTML, Dynamic HTML, JavaScript, CGI, Perl, Grafik, WWW-Seiten, Web-Seiten, Hilfe, Dokumentation, Beschreibung etc. */ $content .= get_meta_data("http://www.example.com/", "description"); /* output looks like this: SELFHTML 8.1.2 - Die bekannte Dokumentation zu HTML, JavaScript und CGI/Perl - Tutorial und Referenz, mit etlichen Zusatztips zu Design, Grafik, Projektverwaltung usw. */ ?> --was-- <?php /* ** Extracts and formats meta tag content */ 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 .= '<p><span style="display:block;color:#000000;font-weight:bold;">' . $key . ' <span style="font-weight:normal;">(' . count($array) . ' words | ' . strlen($value) . ' chars)</span></span>' . $value . '</p>'; // format data with count of words and chars } } return $str; } $content .= get_meta_data("http://de.selfhtml.org/"); /* output looks like this: description (23 words | 167 chars) SELFHTML 8.1.2 - Die bekannte Dokumentation zu HTML, JavaScript und CGI/Perl - Tutorial und Referenz, mit etlichen Zusatztips zu Design, Grafik, Projektverwaltung usw. keywords (13 words | 119 chars) SELFHTML, HTML, Dynamic HTML, JavaScript, CGI, Perl, Grafik, WWW-Seiten, Web-Seiten, Hilfe, Dokumentation, Beschreibung etc. */ $content .= get_meta_data("http://de.selfhtml.org/", "description"); /* output looks like this: SELFHTML 8.1.2 - Die bekannte Dokumentation zu HTML, JavaScript und CGI/Perl - Tutorial und Referenz, mit etlichen Zusatztips zu Design, Grafik, Projektverwaltung usw. */ ?> http://php.net/manual/en/function.get-meta-tags.php

« previous php.notes (#147031) next »