Take the 2-minute tour ×

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'];     // keywords
echo $tags['description'];  //description
share|improve this question
yeah !!! thanks for that –  Jose H d Jan 7 '11 at 17:11
it's not the parsing method that's slow, it's the network latency. get_meta_tags is probably the best way. the only other way would be to load the file into a DOM parser, which would take just as long i'm guessing. –  dqhendricks Jan 7 '11 at 17:16
for what do you need the tags? how much does it slow you down? are you sure it's not something else that slows you down? isn't everything you do slowing you down because that's the physical world? honestly, the question, the way you ask it, puts a smile on my face... that's probably why the col. shrapnel aka harry potter awarded you the magic wand. –  markus Jan 7 '11 at 17:18

1 Answer 1

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

share|improve this answer
wrong, get_meta_data stops when it meets first </head>. Before that it reads file line by line –  German Rumm Jan 9 '11 at 17:33

Your Answer


