mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-18 05:26:57 +08:00
218 lines
7.1 KiB
HTML
218 lines
7.1 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.fnmatch" class="refentry">
|
|
<div class="refnamediv">
|
|
<h1 class="refname">fnmatch</h1>
|
|
<p class="verinfo">(PHP 4 >= 4.3.0, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">fnmatch</span> — <span class="dc-title">用模式匹配文件名</span></p>
|
|
|
|
</div>
|
|
|
|
<div class="refsect1 description" id="refsect1-function.fnmatch-description">
|
|
<h3 class="title">说明</h3>
|
|
<div class="methodsynopsis dc-description">
|
|
<span class="methodname"><strong>fnmatch</strong></span>
|
|
( <span class="methodparam"><span class="type">string</span> <code class="parameter">$pattern</code></span>
|
|
, <span class="methodparam"><span class="type">string</span> <code class="parameter">$string</code></span>
|
|
[, <span class="methodparam"><span class="type">int</span> <code class="parameter">$flags</code><span class="initializer"> = 0</span></span>
|
|
] ) : <span class="type">bool</span></div>
|
|
|
|
<p class="para rdfs-comment">
|
|
<span class="function"><strong>fnmatch()</strong></span>
|
|
检查传入的
|
|
<code class="parameter">string</code>
|
|
是否匹配给出的 shell 统配符
|
|
<code class="parameter">pattern</code>。
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 parameters" id="refsect1-function.fnmatch-parameters">
|
|
<h3 class="title">参数</h3>
|
|
<p class="para">
|
|
<dl>
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">pattern</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
shell 统配符。
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">string</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
要检查的字符串。
|
|
此函数对于文件名尤其有用,但也可以用于普通的字符串。
|
|
</p>
|
|
<p class="para">
|
|
普通用户可能习惯于
|
|
shell 模式或者至少其中最简单的形式
|
|
<em>'?'</em> 和 <em>'*'</em>
|
|
通配符,因此使用
|
|
<span class="function"><strong>fnmatch()</strong></span>
|
|
来代替
|
|
<span class="function"><a href="preg_match.html" class="function">preg_match()</a></span>
|
|
来进行前端搜索表达式输入对于非程序员用户更加方便。
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">flags</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
The value of <code class="parameter">flags</code> can be any combination of
|
|
the following flags, joined with the
|
|
<a href="language.operators.bitwise.html" class="link">binary OR (|) operator</a>.
|
|
<table class="doctable table">
|
|
<caption><strong>
|
|
A list of possible flags for <span class="function"><strong>fnmatch()</strong></span>
|
|
</strong></caption>
|
|
|
|
<thead>
|
|
<tr>
|
|
<th><code class="parameter">Flag</code></th>
|
|
<th>Description</th>
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody class="tbody">
|
|
<tr>
|
|
<td><strong><code>FNM_NOESCAPE</code></strong></td>
|
|
<td>
|
|
Disable backslash escaping.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><strong><code>FNM_PATHNAME</code></strong></td>
|
|
<td>
|
|
Slash in string only matches slash in the given pattern.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><strong><code>FNM_PERIOD</code></strong></td>
|
|
<td>
|
|
Leading period in string must be exactly matched by period in the given pattern.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><strong><code>FNM_CASEFOLD</code></strong></td>
|
|
<td>
|
|
Caseless match. Part of the GNU extension.
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
</dl>
|
|
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 returnvalues" id="refsect1-function.fnmatch-returnvalues">
|
|
<h3 class="title">返回值</h3>
|
|
<p class="para">
|
|
匹配则返回 <strong><code>TRUE</code></strong>,否则返回 <strong><code>FALSE</code></strong>。
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 changelog" id="refsect1-function.fnmatch-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.3.0</td>
|
|
<td>
|
|
此函数开始在 Windows 平台上生效。
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 examples" id="refsect1-function.fnmatch-examples">
|
|
<h3 class="title">范例</h3>
|
|
<p class="para">
|
|
<div class="example" id="example-2797">
|
|
<p><strong>Example #1 用 shell 中的通配符模式匹配来检查颜色名称</strong></p>
|
|
<div class="example-contents">
|
|
<div class="phpcode"><pre><span style="color: #000000">
|
|
<span style="color: #0000BB"><?php<br /></span><span style="color: #007700">if (</span><span style="color: #0000BB">fnmatch</span><span style="color: #007700">(</span><span style="color: #DD0000">"*gr[ae]y"</span><span style="color: #007700">, </span><span style="color: #0000BB">$color</span><span style="color: #007700">)) {<br /> echo </span><span style="color: #DD0000">"some form of gray ..."</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?></span>
|
|
</span>
|
|
</pre></div>
|
|
</div>
|
|
|
|
</div>
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 notes" id="refsect1-function.fnmatch-notes">
|
|
<h3 class="title">注释</h3>
|
|
<div class="warning"><strong class="warning">Warning</strong>
|
|
<p class="para">
|
|
目前该函数无法在 Windows 或其它非 POSIX 兼容的系统上使用。
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 seealso" id="refsect1-function.fnmatch-seealso">
|
|
<h3 class="title">参见</h3>
|
|
<p class="para">
|
|
<ul class="simplelist">
|
|
<li class="member"><span class="function"><a href="glob.html" class="function" rel="rdfs-seeAlso">glob()</a> - 寻找与模式匹配的文件路径</span></li>
|
|
<li class="member"><span class="function"><a href="preg_match.html" class="function" rel="rdfs-seeAlso">preg_match()</a> - 执行匹配正则表达式</span></li>
|
|
<li class="member"><span class="function"><a href="sscanf.html" class="function" rel="rdfs-seeAlso">sscanf()</a> - 根据指定格式解析输入的字符</span></li>
|
|
<li class="member"><span class="function"><a href="printf.html" class="function" rel="rdfs-seeAlso">printf()</a> - 输出格式化字符串</span></li>
|
|
<li class="member"><span class="function"><a href="sprintf.html" class="function" rel="rdfs-seeAlso">sprintf()</a> - Return a formatted string</span></li>
|
|
</ul>
|
|
</p>
|
|
</div>
|
|
|
|
|
|
</div></div></div></body></html> |