1. Use the basename function directly
basename()
The function returns the file name part of the path.
<?php $full_name = 'c:\wamp\php\php.ini'; $base = basename($full_name); // $base is "php.ini" ?>
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('/www/htdocs/inc/lib.inc.php'); echo $path_parts['dirname'], "\n"; echo $path_parts['basename'], "\n"; echo $path_parts['extension'], "\n"; echo $path_parts['filename'], "\n"; // since PHP 5.2.0 ?>
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 ] )
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!