• PHP Video Tutorials

PHP - get_meta_tags() Function



get_meta_tags() function can extract all meta tag content attributes from a file and can return an array.

Syntax

array get_meta_tags( string $filename [, bool $use_include_path = false ] )

get_meta_tags() function can open filename and parse it line by line for <meta> tags in a file. The parsing stops at </head>.

get_meta_tags() function can return an array with all parsed meta tags.

The value of the name property becomes key, the value of the content property becomes the value of the returned array, so we can easily use standard array functions to traverse it or access single values. The special characters in the value of name property are substituted with "_", the rest is converted to lower case. If two meta tags with the same name, only the last one is returned.

Example-1

<head>
   <meta name="author" content="name">
   <meta name="keywords" content="php documentation">
   <meta name="DESCRIPTION" content="a php manual">
   <meta name="geo.position" content="49.33;-86.59">
</head> <!-- parsing stops here -->

Example-2

<?php
   $tags = get_meta_tags("http://www.tutorialspoint.com/");

   echo $tags["author"];  // name
   echo $tags["keywords"];  // php documentation
   echo $tags["description"];  // a php manual
   echo $tags["geo_position"];  // 49.33;-86.59
?>
php_function_reference.htm
Advertisements