-
Notifications
You must be signed in to change notification settings - Fork 105
/
Copy pathglob.xml
182 lines (175 loc) · 4.94 KB
/
glob.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 5fb1bb4a70dc9cf2538d9a78f423579b805137b4 Maintainer: HonestQiao Status: ready -->
<!-- CREDITS: Luffy, mowangjuanzi -->
<refentry xml:id="function.glob" xmlns="http://docbook.org/ns/docbook" xmlns:xi="http://www.w3.org/2001/XInclude">
<refnamediv>
<refname>glob</refname>
<refpurpose>寻找与模式匹配的文件路径</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type class="union"><type>array</type><type>false</type></type><methodname>glob</methodname>
<methodparam><type>string</type><parameter>pattern</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>flags</parameter><initializer>0</initializer></methodparam>
</methodsynopsis>
<para>
<function>glob</function> 函数依照 libc glob() 函数使用的规则寻找所有与
<parameter>pattern</parameter> 匹配的文件路径,类似于一般 shells
所用的规则一样。
</para>
<simpara>
Unix 系统和 macOS 上的行为由系统级 glob() 实现来决定。在 Windows 上,使用符合
POSIX 1003.2 定义的 glob() 实现,它包含一个扩展来处理 <literal>[!...]</literal> 约定以否定范围。
</simpara>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>pattern</parameter></term>
<listitem>
<para>
匹配模式(pattern)。
不进行缩写扩展或参数替代。
</para>
<para>
特殊字符:
<itemizedlist>
<listitem>
<simpara>
<literal>*</literal> - 匹配零个或多个字符。
</simpara>
</listitem>
<listitem>
<simpara>
<literal>?</literal> - 只匹配单个字符(任意字符)。
</simpara>
</listitem>
<listitem>
<simpara>
<literal>[...]</literal> - 匹配一组字符中的一个字符。
如果第一个字符是 <literal>!</literal>,则为否定模式,
即匹配不在这组字符中的任意字符。
</simpara>
</listitem>
<listitem>
<simpara>
<literal>\</literal> - 只要没有使用 <constant>GLOB_NOESCAPE</constant> 标记,该字符会转义后面的字符。
</simpara>
</listitem>
</itemizedlist>
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>flags</parameter></term>
<listitem>
<para>
任何 <constant>GLOB_<replaceable>*</replaceable></constant> 常量。
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
返回包含有匹配文件和目录的数组,没有匹配文件时返回空数组,出错返回
&false;。除非使用了 <literal>GLOB_NOSORT</literal>,否则名称将按字母顺序排序。
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>怎样用 <function>glob</function> 方便地替代
<function>opendir</function> 和相关函数</title>
<programlisting role="php">
<![CDATA[
<?php
foreach (glob("*.txt") as $filename) {
echo "$filename size " . filesize($filename) . "\n";
}
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
funclist.txt size 44686
funcsummary.txt size 267625
quickref.txt size 137820
]]>
</screen>
</example>
<example>
<title>
更复杂模式的示例
</title>
<programlisting role="php">
<![CDATA[
<?php
foreach (glob("path/*/*.{txt,md}", \GLOB_BRACE) as $filename) {
echo "$filename\n";
}
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
path/docs/mailinglist-rules.md
path/docs/README.md
path/docs/release-process.md
path/pear/install-pear.txt
path/Zend/README.md
]]>
</screen>
</example>
</para>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
¬e.no-remote;
<note>
<simpara>
此函数在一些系统上还不能工作(例如一些旧的 Sun OS)。
</simpara>
</note>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>opendir</function></member>
<member><function>readdir</function></member>
<member><function>closedir</function></member>
<member><function>fnmatch</function></member>
</simplelist>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->