PHP basename()関数
❮PHPファイルシステムリファレンス例
指定されたパスからファイル名を返します。
<?php
$path = "/testweb/home.php";
//Show filename
echo basename($path) ."<br/>";
//Show filename, but cut off file extension for ".php" files
echo basename($path,".php");
?>
上記のコードの出力は次のようになります。
home.php
home
定義と使用法
basename()関数は、パスからファイル名を返します。
構文
basename(path, suffix)
パラメータ値
Parameter | Description |
---|---|
path | Required. Specifies a file path |
suffix | Optional. A file extension. If the filename has this file extension, the file extension will be cut off |
技術的な詳細
戻り値: | 指定されたパスのファイル名 |
---|---|
PHPバージョン: | 4.0以降 |
❮PHPファイルシステムリファレンス