Sophie

Sophie

distrib > Mageia > 4 > i586 > by-pkgid > f800694edefe91adea2624f711a41a2d > files > 5073

php-manual-en-5.5.7-1.mga4.noarch.rpm

<!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>Returns information about a file path</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.parse-ini-string.html">parse_ini_string</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.pclose.html">pclose</a></div>
 <div class="up"><a href="ref.filesystem.html">Filesystem Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.pathinfo" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">pathinfo</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.3, PHP 5)</p><p class="refpurpose"><span class="refname">pathinfo</span> &mdash; <span class="dc-title">Returns information about a file path</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.pathinfo-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <span class="methodname"><strong>pathinfo</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$path</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$options</code><span class="initializer"> = PATHINFO_DIRNAME | PATHINFO_BASENAME | PATHINFO_EXTENSION | PATHINFO_FILENAME</span></span>
  ] )</div>

  <p class="para rdfs-comment">
    <span class="function"><strong>pathinfo()</strong></span> returns information about
   <em><code class="parameter">path</code></em>: either an associative array or a string,
   depending on <em><code class="parameter">options</code></em>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.pathinfo-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>

    <dt>

     <span class="term"><em><code class="parameter">path</code></em></span>
     <dd>

      <p class="para">
       The path to be parsed.
      </p>
     </dd>

    </dt>

    <dt>

     <span class="term"><em><code class="parameter">options</code></em></span>
     <dd>

      <p class="para">
       If present, specifies a specific element to be returned; one of
       <strong><code>PATHINFO_DIRNAME</code></strong>,
       <strong><code>PATHINFO_BASENAME</code></strong>,
       <strong><code>PATHINFO_EXTENSION</code></strong> or
       <strong><code>PATHINFO_FILENAME</code></strong>.
      </p>
      <p class="para">If <em><code class="parameter">options</code></em> is not specified, returns all
       available elements.
      </p>
     </dd>

    </dt>

   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.pathinfo-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   If the <em><code class="parameter">options</code></em> parameter is not passed, an
   associative <span class="type"><a href="language.types.array.html" class="type array">array</a></span> containing the following elements is
   returned:
   <em>dirname</em>, <em>basename</em>,
   <em>extension</em> (if any), and <em>filename</em>.
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    If the <em><code class="parameter">path</code></em> has more than one extension,
    <strong><code>PATHINFO_EXTENSION</code></strong> returns only the last one and
    <strong><code>PATHINFO_FILENAME</code></strong> only strips the last one.
    (see first example below).
   </p>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    If the <em><code class="parameter">path</code></em> does not have an extension, no
    <em>extension</em> element will be returned
    (see second example below).
   </p>
  </p></blockquote>
  <p class="para">
   If <em><code class="parameter">options</code></em> is present, returns a
   <span class="type"><a href="language.types.string.html" class="type string">string</a></span> containing the requested element.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.pathinfo-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>5.2.0</td>
       <td>
        The <strong><code>PATHINFO_FILENAME</code></strong> constant was added.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.pathinfo-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-2417">
    <p><strong>Example #1  <span class="function"><strong>pathinfo()</strong></span> Example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$path_parts&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">pathinfo</span><span style="color: #007700">(</span><span style="color: #DD0000">'/www/htdocs/inc/lib.inc.php'</span><span style="color: #007700">);<br /><br />echo&nbsp;</span><span style="color: #0000BB">$path_parts</span><span style="color: #007700">[</span><span style="color: #DD0000">'dirname'</span><span style="color: #007700">],&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />echo&nbsp;</span><span style="color: #0000BB">$path_parts</span><span style="color: #007700">[</span><span style="color: #DD0000">'basename'</span><span style="color: #007700">],&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />echo&nbsp;</span><span style="color: #0000BB">$path_parts</span><span style="color: #007700">[</span><span style="color: #DD0000">'extension'</span><span style="color: #007700">],&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />echo&nbsp;</span><span style="color: #0000BB">$path_parts</span><span style="color: #007700">[</span><span style="color: #DD0000">'filename'</span><span style="color: #007700">],&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;&nbsp;</span><span style="color: #FF8000">//&nbsp;since&nbsp;PHP&nbsp;5.2.0<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>The above example will output:</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
/www/htdocs/inc
lib.inc.php
php
lib.inc
</pre></div>
    </div>
   </div>
  </p>
  <p class="para">
   <div class="example" id="example-2418">
    <p><strong>Example #2  <span class="function"><strong>pathinfo()</strong></span> example showing difference between null and no extension</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$path_parts&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">pathinfo</span><span style="color: #007700">(</span><span style="color: #DD0000">'/path/emptyextension.'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$path_parts</span><span style="color: #007700">[</span><span style="color: #DD0000">'extension'</span><span style="color: #007700">]);<br /><br /></span><span style="color: #0000BB">$path_parts&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">pathinfo</span><span style="color: #007700">(</span><span style="color: #DD0000">'/path/noextension'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$path_parts</span><span style="color: #007700">[</span><span style="color: #DD0000">'extension'</span><span style="color: #007700">]);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>The above example will output
something similar to:</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
string(0) &quot;&quot;

Notice: Undefined index: extension in test.php on line 6
NULL
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.pathinfo-notes">
  <h3 class="title">Notes</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    For information on retrieving the current path info, read
    the section on <a href="language.variables.predefined.html" class="link">
    predefined reserved variables</a>.
   </p>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
     <span class="function"><strong>pathinfo()</strong></span> is locale aware, so for it to parse a path
    containing multibyte characters correctly, the matching locale must be set using
    the  <span class="function"><a href="function.setlocale.html" class="function">setlocale()</a></span> function.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.pathinfo-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"> <span class="function"><a href="function.dirname.html" class="function" rel="rdfs-seeAlso">dirname()</a> - Returns parent directory's path</span></li>
    <li class="member"> <span class="function"><a href="function.basename.html" class="function" rel="rdfs-seeAlso">basename()</a> - Returns trailing name component of path</span></li>
    <li class="member"> <span class="function"><a href="function.parse-url.html" class="function" rel="rdfs-seeAlso">parse_url()</a> - Parse a URL and return its components</span></li>
    <li class="member"> <span class="function"><a href="function.realpath.html" class="function" rel="rdfs-seeAlso">realpath()</a> - Returns canonicalized absolute pathname</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.parse-ini-string.html">parse_ini_string</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.pclose.html">pclose</a></div>
 <div class="up"><a href="ref.filesystem.html">Filesystem Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>