i need a regex for ectract meta title, description

exg:
<meta name="description" content="xxxxx">
and
<meta name="Description" content="xxxxx">
and
<meta name="Descriptions" content="xxxxx">
and
<Meta name="Descriptions" content="xxxxx">
and
<META NAME="Description" content="xxxxx">

i want to extract all type od descrptions, same also meta title

Recommended Answers

You probably don't need regex, you can try get_meta_tags():

http://us2.php.net/manual/en/function.get-meta-tags.php

Jump to Post

All 4 Replies

thanks your reply, its not getting uppercase meta tage
eg:
<META NAME="DESCRIPTION"
<meta name="Descriptions"

Member Avatar

Be aware that array keys are case sensitive.

Did you try

$tags = get_meta_tags('http://www.example.com/');

echo $tags['DESCRIPTION'];   
echo $tags['Descriptions'];     
Member Avatar

What you can do is strtolower the keys in the $tags array and check those.

function cleanMeta($tags)
{
    $keys = array_map('strtolower', array_keys($tags));
    $values = array_values($tags);
    return array_combine($keys, $values);
}

$tags = cleanMeta(get_meta_tags('hangman.php'));

print_r($tags);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.