Home > Backend Development > PHP Problem > What are the ways to get the file name in the path in php

What are the ways to get the file name in the path in php

王林
Release: 2023-02-28 17:00:01
Original
6133 people have browsed it

What are the ways to get the file name in the path in php

1. Use the basename function directly

basename() The function returns the file name part of the path.

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

Online video tutorial sharing: php video tutorial

2. Use the pathinfo function

pathinfo() The function takes an array Returns information about the file path.

<?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. Use the explode function

explode() The function uses one string to split another string and returns an array composed of strings.

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

Recommended related articles and tutorials: php tutorial

The above is the detailed content of What are the ways to get the file name in the path in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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