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.