Home > Backend Development > PHP Tutorial > php如何获取文件名

php如何获取文件名

PHPz
Release: 2020-09-04 17:33:18
Original
8756 people have browsed it

php获取文件名的方法:可以用basename()函数来获取文件名,例如:【basename($full_name)】。还可以使用pathinfo()函数来获取文件名。

php如何获取文件名

PHP中获取文件名的方式

1、直接用basename:

<?php
$full_name = &#39;c:\wamp\php\php.ini&#39;;
$base = basename($full_name); // $base is "php.ini"
$dir = dirname($full_name);  // $dir is "c:\wamp\php"
?>
Copy after login

2、pathinfo:

<?php
$path_parts = pathinfo(&#39;/www/htdocs/inc/lib.inc.php&#39;);
 
echo $path_parts[&#39;dirname&#39;], "\n";
echo $path_parts[&#39;basename&#39;], "\n";
echo $path_parts[&#39;extension&#39;], "\n";
echo $path_parts[&#39;filename&#39;], "\n"; // since PHP 5.2.0
?>
Copy after login

3、explode :使用一个字符串分割另一个字符串

array explode ( string $delimiter , string $string [, int $limit ] )
Copy after login

更多相关知识,请访问 PHP中文网!!

Related labels:
php
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template