I was wondering: which is the fastest method or code to get meta tags?
I have this code with me, but using get_meta_tags
function slows down the process. Any ideas?
$tags = get_meta_tags('http://www.example.com/');
echo $tags['keywords']; // key开发者_高级运维words
echo $tags['description']; //description
The reason is because the whole page is parsed before php attempts to get the meta tags. It is probably best to use a regex to parse the returned html.
function get_meta_data($page) { $meta_data = array(); preg_match_all( "/]+name=\"([^"])\"[^>]+content="([^\"])"[^>]+>/i", $page, $result, PREG_PATTERN_ORDER);
$total_found = count($result[1]);
while (--$total_found) {
strtolower($out[1][$i]) == "keywords") && $meta_data['keywords'] = $results[2][$i];
strtolower($out[1][$i]) == "description") && $meta_data['description'] = $results[2][$i];
}
return $meta;
}
hope that helps
精彩评论