English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP 基础教程

PHP 高级教程

PHP & MySQL

PHP 参考手册

PHP basename() 函数用法及示例

PHP Filesystem 参考手册

basename()函数可返回路径中的文件名部分。

语法

string basename ( string path [, string suffix] )

它给出了一个包含文件路径的字符串,并且此函数返回文件的基本名称。如果文件名以后缀结尾,也可以将其截断。

在线示例

<?php
   $path = "/PhpProject/index.php";
   $file = basename($path);  //  $file 设置为 "index.php"
   echo $file . "\n";
   
   $file = basename($path, ".php");  // $file 设置为 "index"
   echo $file;
?>

输出结果

index.php
index

PHP Filesystem 参考手册