mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-18 13:57:03 +08:00
192 lines
9.3 KiB
HTML
192 lines
9.3 KiB
HTML
<!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>返回文件路径的信息</title>
|
||
</head>
|
||
<body class="docs"><div id="layout">
|
||
<div id="layout-content"><div id="function.pathinfo" class="refentry">
|
||
<div class="refnamediv">
|
||
<h1 class="refname">pathinfo</h1>
|
||
<p class="verinfo">(PHP 4 >= 4.0.3, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">pathinfo</span> — <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">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>
|
||
] ) : <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span></div>
|
||
|
||
<p class="para rdfs-comment">
|
||
<span class="function"><strong>pathinfo()</strong></span> 返回一个关联数组包含有 <em>path</em>
|
||
的信息。返回关联数组还是字符串取决于 <code class="parameter">options</code>。
|
||
</p>
|
||
</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">options</code></dt>
|
||
|
||
<dd>
|
||
|
||
<p class="para">
|
||
如果指定了,将会返回指定元素;它们包括:<strong><code>PATHINFO_DIRNAME</code></strong>,<strong><code>PATHINFO_BASENAME</code></strong>
|
||
和 <strong><code>PATHINFO_EXTENSION</code></strong> 或 <strong><code>PATHINFO_FILENAME</code></strong>。
|
||
</p>
|
||
<p class="para">如果没有指定 <code class="parameter">options</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.html" class="type array">array</a></span>:<em>dirname</em>,<em>basename</em>
|
||
和 <em>extension</em>(如果有),以 及<em>filename</em>。
|
||
</p>
|
||
<blockquote class="note"><p><strong class="note">Note</strong>:
|
||
<p class="para">
|
||
If the <code class="parameter">path</code> does not have an extension, no
|
||
<em>extension</em> element will be returned(以下第二个案例)。
|
||
</p>
|
||
</p></blockquote>
|
||
<p class="para">
|
||
If <code class="parameter">options</code> 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">更新日志</h3>
|
||
<p class="para">
|
||
<table class="doctable informaltable">
|
||
|
||
<thead>
|
||
<tr>
|
||
<th>版本</th>
|
||
<th>说明</th>
|
||
</tr>
|
||
|
||
</thead>
|
||
|
||
<tbody class="tbody">
|
||
<tr>
|
||
<td>5.2.0</td>
|
||
<td>
|
||
添加了常量 <strong><code>PATHINFO_FILENAME</code></strong>。
|
||
</td>
|
||
</tr>
|
||
|
||
</tbody>
|
||
|
||
</table>
|
||
|
||
</p>
|
||
</div>
|
||
|
||
|
||
<div class="refsect1 examples" id="refsect1-function.pathinfo-examples">
|
||
<h3 class="title">范例</h3>
|
||
<p class="para">
|
||
<div class="example" id="example-2830">
|
||
<p><strong>Example #1 <span class="function"><strong>pathinfo()</strong></span> 例子</strong></p>
|
||
<div class="example-contents">
|
||
<div class="phpcode"><pre><span style="color: #000000">
|
||
<span style="color: #0000BB"><?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">; </span><span style="color: #FF8000">// since PHP 5.2.0<br /></span><span style="color: #0000BB">?></span>
|
||
</span>
|
||
</pre></div>
|
||
</div>
|
||
|
||
<div class="example-contents"><p>以上例程会输出:</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-2831">
|
||
<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"><pre><span style="color: #000000">
|
||
<span style="color: #0000BB"><?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">?></span>
|
||
</span>
|
||
</pre></div>
|
||
</div>
|
||
|
||
<div class="example-contents"><p>以上例程的输出类似于:</p></div>
|
||
<div class="example-contents screen">
|
||
<div class="cdata"><pre>
|
||
string(0) ""
|
||
|
||
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">注释</h3>
|
||
<blockquote class="note"><p><strong class="note">Note</strong>:
|
||
<p class="para">
|
||
有关取得当前路径信息的说明,请阅读<a href="language.variables.predefined.html" class="link">预定义变量</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="setlocale.html" class="function">setlocale()</a></span> function.
|
||
</p>
|
||
</p></blockquote>
|
||
</div>
|
||
|
||
|
||
<div class="refsect1 seealso" id="refsect1-function.pathinfo-seealso">
|
||
<h3 class="title">参见</h3>
|
||
<p class="para">
|
||
<ul class="simplelist">
|
||
<li class="member"><span class="function"><a href="dirname.html" class="function" rel="rdfs-seeAlso">dirname()</a> - 返回路径中的目录部分</span></li>
|
||
<li class="member"><span class="function"><a href="basename.html" class="function" rel="rdfs-seeAlso">basename()</a> - 返回路径中的文件名部分</span></li>
|
||
<li class="member"><span class="function"><a href="parse_url.html" class="function" rel="rdfs-seeAlso">parse_url()</a> - 解析 URL,返回其组成部分</span></li>
|
||
<li class="member"><span class="function"><a href="realpath.html" class="function" rel="rdfs-seeAlso">realpath()</a> - 返回规范化的绝对路径名</span></li>
|
||
</ul>
|
||
</p>
|
||
</div>
|
||
|
||
</div></div></div></body></html> |