編碼的世界 / 優質文選 / 文明

PHP中獲取文件名的方式


2022年7月01日
-   

1.直接用basename:
<?php
$full_name = 'c:wampphpphp.ini';
$base = basename($full_name); // $base is "php.ini"
$dir = dirname($full_name); // $dir is "c:wampphp"
?>

2.pathinfo:
<?php
$path_parts = pathinfo('/www/htdocs/inc/lib.inc.php');
echo $path_parts['dirname'], "
";
echo $path_parts['basename'], "
";
echo $path_parts['extension'], "
";
echo $path_parts['filename'], "
"; // since PHP 5.2.0
?>

3.explode :使用一個字符串分割另一個字符串
array explode ( string $delimiter , string $string [, int $limit ] )

 

熱門文章