PHP glob()関数
❮PHPファイルシステムリファレンス例
指定されたパターンに一致するファイル名またはディレクトリの配列を返します。
<?php
print_r(glob("*.txt"));
?>
上記のコードの出力は次のようになります。
Array
(
[0] => target.txt
[1] => source.txt
[2] => test.txt
[3] => test2.txt
)
定義と使用法
glob()関数は、指定されたパターンに一致するファイル名またはディレクトリの配列を返します。
構文
glob(pattern, flags)
パラメータ値
Parameter | Description |
---|---|
pattern | Required. Specifies the pattern to search for |
flags | Optional. Specifies special settings. Possible values:
|
技術的な詳細
戻り値: | パターンに一致するファイル/ディレクトリの配列、失敗した場合はFALSE |
---|---|
PHPバージョン: | 4.3+ |
PHP変更ログ: | PHP 5.1:フラグパラメータにGLOB_ERR値が追加されました |
その他の例
例
指定されたパターンに一致するファイル名またはディレクトリの配列を返します。
<?php
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
)
❮PHPファイルシステムリファレンス