PhpDig.net

What is PhpDig?
PhpDig is a PHP MySQL based
Web Spider & Search Engine.




get_meta_tags

Name

get_meta_tags — Extracts the meta tag information from a file or URL.

Synopsis

array get_meta_tags(filename_or_url,[, use_include_path,]);
string filename_or_url,: Filename or URL from which to get meta tags
int use_include_path, (optional): Whether to search the include path for the filename

Returns

Associative array; FALSE on error

Description

get_meta_tags() parses the meta tag information from a file or URL. Parsing stops when the closing head tag</head>) is encountered.

Tag information is returned as an associative array. The keys of the array correspond to the name attributes of the meta tags, and the values of the array correspond to the content attributes. If the filename_or_url argument contains a relative filename and use_include_path is set to 1, PHP searches the include path for the file.

The function converts all of the key values to lowercase and replaces any period (.), backslash (\), plus+), asterisk (*), question mark?), bracket ([]), caret^), dollar sign ($), space ( ), and parenthesis (()) characters with the underscore_) character.

Warning

get_meta_tags() is not a robust function. In many situations, the function fails to retrieve all the meta tags from a document. See the following list of conditions.

If the values associated with the name or description attributes are not quoted, the meta tag is not parsed.

    <meta name=foo content=bar> <!-- This tag will not be parsed properly -->


If the meta tag contains a newline, the meta tag is not parsed.

    <meta name="foo"
        content="bar"> <!-- This tag will not be parsed properly -->


If a line contains more than one meta tag, the second and subsequent meta tags are not parsed.

    <meta name="a" content="1"> <!-- Only the first tag is parsed --> <meta name="b" content="2">


Malformed meta tags may parse incorrectly.

    <meta name="a" foo="bar" content="1">
    <meta name="b"
        content="2">
    <!-- If you parse this example using get_meta_tags(), b ends up containing the value for a -->




Version

PHP 3.0.4+, PHP 4+

Example

Example 1201. Simple demo of get_meta_tags()

<pre>
<?php
$URL = 'http://www.newriders.com/';

// Try to fetch the meta tags for $URL
$meta_tags = @ get_meta_tags($URL)
    or die("Could not fetch meta tags for $URL");

// Show the contents of $meta_tags
print_r($meta_tags);
?>
</pre>



PHP Functions Essential Reference. Copyright © 2002 by New Riders Publishing (Authors: Zak Greant, Graeme Merrall, Torben Wilson, Brett Michlitsch). This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later (the latest version is presently available at http://www.opencontent.org/openpub/). The authors of this book have elected not to choose any options under the OPL. This online book was obtained from http://www.fooassociates.com/phpfer/ and is designed to provide information about the PHP programming language, focusing on PHP version 4.0.4 for the most part. The information is provided on an as-is basis, and no warranty or fitness is implied. All persons and entities shall have neither liability nor responsibility to any person or entity with respect to any loss or damage arising from the information contained in this book.

Powered by: vBulletin Version 3.0.7
Copyright ©2000 - 2005, Jelsoft Enterprises Ltd.
Copyright © 2001 - 2005, ThinkDing LLC. All Rights Reserved.