PHP pathinfo()関数
❮PHPファイルシステムリファレンス例
ファイルパスに関する情報を取得します。
<?php
print_r(pathinfo("/testweb/test.txt"));
?>
上記のコードの出力は次のようになります。
Array
(
[dirname] => /testweb
[basename] => test.txt
[extension] => txt
)
定義と使用法
pathinfo()関数は、ファイルパスに関する情報を返します。
構文
pathinfo(path, options)
パラメータ値
Parameter | Description |
---|---|
path | Required. Specifies the path to be checked |
options | Optional. Specifies which array element to return. If not specified, it
returns all elements. Possible values:
|
技術的な詳細
戻り値: | オプションパラメータを省略すると、dirname、basename、extension、filenameの連想配列が返されます。オプションパラメータが指定されている場合、要求された要素を含む文字列を返します。 失敗するとFALSE |
---|---|
PHPバージョン: | 4.0.3+ |
PHP変更ログ: | PHP 5.2:PATHINFO_FILENAMEが追加されました |
その他の例
例
ファイルパスに関する情報を取得します。
<?php
print_r(pathinfo("/testweb/test.txt",PATHINFO_BASENAME));
?>
上記のコードの出力は次のようになります。
test.txt