note 87273 added to function.get-meta-tags

From: Date: Thu, 27 Nov 2008 12:12:05 +0000
Subject: note 87273 added to function.get-meta-tags
Groups: php.notes 
Request: Send a blank email to php-notes+get-147030@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://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. */ ?> ---- Server IP: 212.124.37.9 Probable Submitter: 217.225.13.163 ---- Manual Page -- http://www.php.net/manual/en/function.get-meta-tags.php Edit -- https://master.php.net/note/edit/87273 Del: integrated -- https://master.php.net/note/delete/87273/integrated Del: useless -- https://master.php.net/note/delete/87273/useless Del: bad code -- https://master.php.net/note/delete/87273/bad+code Del: spam -- https://master.php.net/note/delete/87273/spam Del: non-english -- https://master.php.net/note/delete/87273/non-english Del: in docs -- https://master.php.net/note/delete/87273/in+docs Del: other reasons-- https://master.php.net/note/delete/87273 Reject -- https://master.php.net/note/reject/87273 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#147030) next »