ファイル名の取得や拡張子の取得、ディレクトリの取得
ファイル名の取得や拡張子の取得、ディレクトリの取得
<?php
$path_parts = pathinfo("/www/htdocs/index.html");
echo $path_parts["dirname"] . "\n";
echo $path_parts["basename"] . "\n";
echo $path_parts["extension"] . "\n";
?>
出力は次のようになります。
/www/htdocs
index.html
html
ファイル名取得
$path = "/home/httpd/html/index.php";
$file = basename ($path); // $file is set to "index.php"
$file = basename ($path,".php"); // $file is set to "index"