PHP dirname()関数
❮PHPファイルシステムリファレンス例
親ディレクトリのパスを返します。
<?php
echo dirname("c:/testweb/home.php") . "<br />";
echo dirname("c:/testweb/home.php",
2) . "<br />";
echo dirname("/testweb/home.php");
?>
上記のコードの出力は次のようになります。
c:/testweb
c:
/testweb
定義と使用法
dirname()関数は、親ディレクトリのパスを返します。
構文
dirname(path, levels)
パラメータ値
Parameter | Description |
---|---|
path | Required. Specifies a path to check |
levels | Optional. An integer that specifies the number of parent directories to go up. Default is 1 |
技術的な詳細
戻り値: | 成功したときの親ディレクトリのパス |
---|---|
PHPバージョン: | 4.0以降 |
バイナリセーフ: | はい、PHP5.0では |
PHP変更ログ: | PHP7.0-レベルパラメータを追加しました |
❮PHPファイルシステムリファレンス