PHP glob()関数
完全な PHP Filesystem リファレンスマニュアル
定義と使用法
glob() 関数は、指定したパターンに一致するファイル名またはディレクトリを含む配列を返します。
この関数は、一致するファイル/ディレクトリを含む配列を返します。失敗した場合は FALSE を返します。
構文
glob(pattern,flags)
| パラメータ | 説明 |
|---|---|
| pattern | 必須です。検索パターンを指定します。 |
| flags | オプションです。特別な設定を指定します。 指定可能な値:
|
例 1
<?php
print_r(glob("*.txt"));
?>
print_r(glob("*.txt"));
?>
上記のコードの出力:
Array
(
[0] => target.txt
[1] => source.txt
[2] => test.txt
[3] => test2.txt
)
(
[0] => target.txt
[1] => source.txt
[2] => test.txt
[3] => test2.txt
)
例 2
<?php
print_r(glob("*.*"));
?>
print_r(glob("*.*"));
?>
上記のコードの出力:
Array
(
[0] => contacts.csv
[1] => default.php
[2] => target.txt
[3] => source.txt
[4] => tem1.tmp
[5] => test.htm
[6] => test.ini
[7] => test.php
[8] => test.txt
[9] => test2.txt
)
(
[0] => contacts.csv
[1] => default.php
[2] => target.txt
[3] => source.txt
[4] => tem1.tmp
[5] => test.htm
[6] => test.ini
[7] => test.php
[8] => test.txt
[9] => test2.txt
)
完全な PHP Filesystem リファレンスマニュアル その他の拡張