<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.filesystem.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'zh',
  ),
  'this' => 
  array (
    0 => 'function.pathinfo.php',
    1 => 'pathinfo',
    2 => '返回文件路径的信息',
  ),
  'up' => 
  array (
    0 => 'ref.filesystem.php',
    1 => '文件系统函数',
  ),
  'prev' => 
  array (
    0 => 'function.parse-ini-string.php',
    1 => 'parse_ini_string',
  ),
  'next' => 
  array (
    0 => 'function.pclose.php',
    1 => 'pclose',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'zh',
    'path' => 'reference/filesystem/functions/pathinfo.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<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, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">pathinfo</span> &mdash; <span class="dc-title">返回文件路径的信息</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.pathinfo-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>pathinfo</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$path</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$flags</code><span class="initializer"> = <strong><code><a href="filesystem.constants.php#constant.pathinfo-all">PATHINFO_ALL</a></code></strong></span></span>): <span class="type"><span class="type"><a href="language.types.array.php" class="type array">array</a></span>|<span class="type"><a href="language.types.string.php" class="type string">string</a></span></span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>pathinfo()</strong></span> 返回一个关联数组包含有 <code class="parameter">path</code>
   的信息。返回关联数组还是字符串取决于 <code class="parameter">flags</code>。
  </p>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    有关取得当前路径信息的说明，请阅读 <a href="language.variables.predefined.php" class="link">预定义变量</a> 一节。
   </p>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    <span class="function"><strong>pathinfo()</strong></span> 纯粹基于输入字符串操作，
    它不会受实际文件系统和类似 &quot;<code class="literal">..</code>&quot; 的路径格式影响。
   </p>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    反斜线字符 <code class="literal">\</code> 仅在 Windows 系统上会解释为目录分隔符。在其他系统上，它将视为普通字符。
   </p>
  </p></blockquote>
  <div class="caution"><strong class="caution">警告</strong>
   <p class="para">
    <span class="function"><strong>pathinfo()</strong></span> 是本地化的，所以为了让它能正确地解析一个包含多字节编码的路径，
    必须使用 <span class="function"><a href="function.setlocale.php" class="function">setlocale()</a></span> 函数来设置地区信息。
   </p>
  </div>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.pathinfo-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">path</code></dt>
     <dd>
      <p class="para">
       要解析的路径。
      </p>
     </dd>
    
    
     <dt><code class="parameter">flags</code></dt>
     <dd>
      <p class="para">
       如果指定了，将会返回指定元素；它们包括：
       <strong><code><a href="filesystem.constants.php#constant.pathinfo-dirname">PATHINFO_DIRNAME</a></code></strong>、
       <strong><code><a href="filesystem.constants.php#constant.pathinfo-basename">PATHINFO_BASENAME</a></code></strong>、
       <strong><code><a href="filesystem.constants.php#constant.pathinfo-extension">PATHINFO_EXTENSION</a></code></strong>、
       <strong><code><a href="filesystem.constants.php#constant.pathinfo-filename">PATHINFO_FILENAME</a></code></strong>。
      </p>
      <p class="para">如果没有指定 <code class="parameter">flags</code> 默认是返回全部的单元。
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.pathinfo-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   如果没有传入 <code class="parameter">options</code> ，将会返回包括以下单元的数组 <span class="type"><a href="language.types.array.php" class="type array">array</a></span>：<code class="literal">dirname</code>，<code class="literal">basename</code>
   和 <code class="literal">extension</code>（如果有），以及<code class="literal">filename</code>。
  </p>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    如果 <code class="parameter">path</code> 有一个以上的扩展名，
    <strong><code><a href="filesystem.constants.php#constant.pathinfo-extension">PATHINFO_EXTENSION</a></code></strong> 只返回最后一个，而
    <strong><code><a href="filesystem.constants.php#constant.pathinfo-filename">PATHINFO_FILENAME</a></code></strong> 仅剥离最后一个。
    （参考第一个示例）。
   </p>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    如果 <code class="parameter">path</code> 没有扩展名，返回数据中就不会有
    <code class="literal">extension</code> 元素。（参考第二个示例）
   </p>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    如果 <code class="parameter">path</code> 中的 <code class="literal">basename</code> 以点开始，
    那后面的字符串将被解释为 <code class="literal">extension</code> ，
    并且 <code class="literal">filename</code> 为空。（参考第三个示例）
   </p>
  </p></blockquote>
  <p class="para">
   如果 <code class="parameter">flags</code> 存在的，
   则返回一个包含请求元素的 <span class="type"><a href="language.types.string.php" class="type string">string</a></span>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.pathinfo-examples">
  <h3 class="title">示例</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>示例 #1 <span class="function"><strong>pathinfo()</strong></span> 例子</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$path_parts </span><span style="color: #007700">= </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 </span><span style="color: #0000BB">$path_parts</span><span style="color: #007700">[</span><span style="color: #DD0000">'dirname'</span><span style="color: #007700">], </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />echo </span><span style="color: #0000BB">$path_parts</span><span style="color: #007700">[</span><span style="color: #DD0000">'basename'</span><span style="color: #007700">], </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />echo </span><span style="color: #0000BB">$path_parts</span><span style="color: #007700">[</span><span style="color: #DD0000">'extension'</span><span style="color: #007700">], </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />echo </span><span style="color: #0000BB">$path_parts</span><span style="color: #007700">[</span><span style="color: #DD0000">'filename'</span><span style="color: #007700">], </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>以上示例会输出：</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">/www/htdocs/inc
lib.inc.php
php
lib.inc</pre>
</div>
    </div>
   </div>
  </p>
  <p class="para">
   <div class="example" id="example-2">
    <p><strong>示例 #2 <span class="function"><strong>pathinfo()</strong></span> 对比空扩展名和无扩展名之间区别的示例</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$path_parts </span><span style="color: #007700">= </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 </span><span style="color: #007700">= </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>以上示例的输出类似于：</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">string(0) &quot;&quot;

Notice: Undefined index: extension in test.php on line 6
NULL</pre>
</div>
    </div>
   </div>
  </p>
  <p class="para">
   <div class="example" id="example-3">
    <p><strong>示例 #3 <span class="function"><strong>pathinfo()</strong></span> 形如 .file 的示例</strong></p>
    <div class="example-contents">
     <div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">pathinfo</span><span style="color: #007700">(</span><span style="color: #DD0000">'/some/path/.test'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>以上示例的输出类似于：</p></div>
    <div class="example-contents screen">
     <div class="examplescode"><pre class="examplescode">Array
(
    [dirname] =&gt; /some/path
    [basename] =&gt; .test
    [extension] =&gt; test
    [filename] =&gt;
)</pre>
</div>
    </div>
   </div>
  </p>
  <p class="para">
   <div class="example" id="example-4">
    <p><strong>示例 #4 <span class="function"><strong>pathinfo()</strong></span> 示例和解除数组引用</strong></p>
    <div class="example-contents"><p>
     <code class="parameter">flags</code> 参数不是位掩码。只能提供单个值。要是只选择某些格式化值，请使用数组解构，如下所示：
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">[</span><span style="color: #DD0000">'basename' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">$basename</span><span style="color: #007700">, </span><span style="color: #DD0000">'dirname' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">$dirname</span><span style="color: #007700">] = </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 /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$basename</span><span style="color: #007700">, </span><span style="color: #0000BB">$dirname</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>以上示例的输出类似于：</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">string(11) &quot;lib.inc.php&quot;
string(15) &quot;/www/htdocs/inc&quot;</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.pathinfo-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.dirname.php" class="function" rel="rdfs-seeAlso">dirname()</a> - 返回路径中的目录部分</span></li>
    <li><span class="function"><a href="function.basename.php" class="function" rel="rdfs-seeAlso">basename()</a> - 返回路径中的文件名部分</span></li>
    <li><span class="function"><a href="function.parse-url.php" class="function" rel="rdfs-seeAlso">parse_url()</a> - 解析 URL，返回其组成部分</span></li>
    <li><span class="function"><a href="function.realpath.php" class="function" rel="rdfs-seeAlso">realpath()</a> - 返回规范化的绝对路径名</span></li>
   </ul>
  </p>
 </div>


</div><?php manual_footer($setup); ?>