mirror of
https://github.com/php/doc-ja.git
synced 2026-04-26 09:28:10 +02:00
195 lines
5.7 KiB
XML
195 lines
5.7 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: bb9bfdfc5a4a8ffe27ab4edcfe0d8747a375e2f2 Maintainer: mumumu Status: ready -->
|
|
<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> にマッチする全てのパス名を検索します。
|
|
ルールは、一般のシェルで使われるルールと似ています。
|
|
</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>
|
|
パターン。チルダの展開やパラメータ置換は行いません。
|
|
</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>{a,b,c}</literal> - <constant>GLOB_BRACE</constant> フラグを使った場合に、コンマで区切った文字列のグループのうち、ひとつにマッチします。
|
|
</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
|
|
-->
|