note 56980 added to function.get-meta-tags
| From: | jimmyxx at gmail dot com | Date: | Tue, 20 Sep 2005 19:37:15 +0000 |
| Subject: | note 56980 added to function.get-meta-tags | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-95500@lists.php.net to get a copy of this message | ||
I used this as part of my mini php search based search engine - it really slowed the whole thing
down. I wrote this function to read HTML (just fetch the file or use something like snoopy) and
extract the meta data via a simple regex, works a treat and made my crawler much faster:
<?php
function get_meta_data($html) {
preg_match_all(
"|<meta[^>]+name=\\"([^\\"]*)\\"[^>]+content=\\"([^\\"]*)\\"[^>]+>|i",
$html, $out,PREG_PATTERN_ORDER);
for ($i=0;$i < count($out[1]);$i++) {
// loop through the meta data - add your own tags here if you need
if (strtolower($out[1][$i]) == "keywords") $meta['keywords'] = $out[2][$i];
if (strtolower($out[1][$i]) == "description") $meta['description'] =
$out[2][$i];
}
return $meta;
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.get-meta-tags.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+56980
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56980&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56980&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56980&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56980&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56980&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+56980&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56980&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+56980&report=yes
Search -- http://master.php.net/manage/user-notes.php