You may not know the PHP get_meta_tags () function

Source: Internet
Author: User

Definition and usage:

Get_meta_tags-extract all meta tag content attributes from a file and return an array

Syntax:

Copy codeThe Code is as follows: array get_meta_tags (string filename, int [use_include_path]);
# Open the <meta> label in the filename line-by-line parsing file. Resolution stops at

Parameters Description
Filename

Path string of the HTML file

This parameter can be a local file or a URL.

Example #1 What does get_meta_tags () Parse?

<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> <! -- Resolution stops here -->

(Note: Press enter to wrap the line-PHP uses a local function to parse the input, so files on Mac won't work normally on Unix ).

Use_include_path Setting use_include_path to TRUE will enable PHP to try to open the file according to each point in the include_path standard. This is only used for local files and does not apply to URLs.

Return Value

Returns an array containing all parsed meta tags.
The returned joined array uses the value of attribute name as the key and the value of attribute content as the value, so you can easily use the standard Array Function to traverse the joined array or access a value. Special characters in the property name are replaced with '_', while other characters are converted to lowercase letters. If two meta tags have the same name, only the last one is returned.

Example

Copy codeThe Code is as follows:
// Assume that the above label is in www.jb51.net
$ Tags = get_meta_tags ('HTTP: // www.jb51.net ');

// Note that all keys are in lowercase, and '.' In the key is converted '_'.
Echo $ tags ['author']; // dxy | www.jb51.net
Echo $ tags ['keyword']; // script, vbscript, regular expression, jquery, dos, bat, batch processing, javascript, Photoshop, HTML, div + css, ASP, PHP, ASP. NET
Echo $ tags ['description']; // a professional website construction resource and Script Programming learning website in China, provides programming materials such as asp, php, asp.net, javascript, jquery, vbscript, dos batch processing, web page creation, network programming, and website construction.

Note

Only meta tags containing the name attribute are parsed.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.