<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Extracts all meta tag content attributes from a file and returns an array</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.get-headers.html">get_headers</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.http-build-query.html">http_build_query</a></div> <div class="up"><a href="ref.url.html">URL Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.get-meta-tags" class="refentry"> <div class="refnamediv"> <h1 class="refname">get_meta_tags</h1> <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">get_meta_tags</span> — <span class="dc-title">Extracts all meta tag content attributes from a file and returns an array</span></p> </div> <div class="refsect1 description" id="refsect1-function.get-meta-tags-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">array</span> <span class="methodname"><strong>get_meta_tags</strong></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$filename</code></span> [, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$use_include_path</code><span class="initializer"> = false</span></span> ] )</div> <p class="para rdfs-comment"> Opens <em><code class="parameter">filename</code></em> and parses it line by line for <meta> tags in the file. The parsing stops at <em></head></em>. </p> </div> <div class="refsect1 parameters" id="refsect1-function.get-meta-tags-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">filename</code></em></span> <dd> <p class="para"> The path to the HTML file, as a string. This can be a local file or an <acronym title="Uniform Resource Locator">URL</acronym>. </p> <p class="para"> <div class="example" id="example-4083"> <p><strong>Example #1 What <span class="function"><strong>get_meta_tags()</strong></span> parses</strong></p> <div class="example-contents"> <div class="htmlcode"><pre class="htmlcode"><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 --></pre> </div> </div> </div> (pay attention to line endings - PHP uses a native function to parse the input, so a Mac file won't work on Unix). </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">use_include_path</code></em></span> <dd> <p class="para"> Setting <em><code class="parameter">use_include_path</code></em> to <strong><code>TRUE</code></strong> will result in PHP trying to open the file along the standard include path as per the <a href="ini.core.html#ini.include-path" class="link">include_path</a> directive. This is used for local files, not URLs. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.get-meta-tags-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns an array with all the parsed meta tags. </p> <p class="para"> The value of the name property becomes the key, the value of the content property becomes the value of the returned array, so you can easily use standard array functions to traverse it or access single values. Special characters in the value of the name property are substituted with '_', the rest is converted to lower case. If two meta tags have the same name, only the last one is returned. </p> </div> <div class="refsect1 changelog" id="refsect1-function.get-meta-tags-changelog"> <h3 class="title">Changelog</h3> <p class="para"> <table class="doctable informaltable"> <thead> <tr> <th>Version</th> <th>Description</th> </tr> </thead> <tbody class="tbody"> <tr> <td>4.0.5</td> <td> Support for unquoted HTML attributes was added. </td> </tr> </tbody> </table> </p> </div> <div class="refsect1 examples" id="refsect1-function.get-meta-tags-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-4084"> <p><strong>Example #2 What <span class="function"><strong>get_meta_tags()</strong></span> returns</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">// Assuming the above tags are at www.example.com<br /></span><span style="color: #0000BB">$tags </span><span style="color: #007700">= </span><span style="color: #0000BB">get_meta_tags</span><span style="color: #007700">(</span><span style="color: #DD0000">'http://www.example.com/'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Notice how the keys are all lowercase now, and<br />// how . was replaced by _ in the key.<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">$tags</span><span style="color: #007700">[</span><span style="color: #DD0000">'author'</span><span style="color: #007700">]; </span><span style="color: #FF8000">// name<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">$tags</span><span style="color: #007700">[</span><span style="color: #DD0000">'keywords'</span><span style="color: #007700">]; </span><span style="color: #FF8000">// php documentation<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">$tags</span><span style="color: #007700">[</span><span style="color: #DD0000">'description'</span><span style="color: #007700">]; </span><span style="color: #FF8000">// a php manual<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">$tags</span><span style="color: #007700">[</span><span style="color: #DD0000">'geo_position'</span><span style="color: #007700">]; </span><span style="color: #FF8000">// 49.33;-86.59<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> </div> <div class="refsect1 notes" id="refsect1-function.get-meta-tags-notes"> <h3 class="title">Notes</h3> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> Only meta tags with name attributes will be parsed. </p> </p></blockquote> </div> <div class="refsect1 seealso" id="refsect1-function.get-meta-tags-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="function.htmlentities.html" class="function" rel="rdfs-seeAlso">htmlentities()</a> - Convert all applicable characters to HTML entities</span></li> <li class="member"> <span class="function"><a href="function.urlencode.html" class="function" rel="rdfs-seeAlso">urlencode()</a> - URL-encodes string</span></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.get-headers.html">get_headers</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.http-build-query.html">http_build_query</a></div> <div class="up"><a href="ref.url.html">URL Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>