php gets the file suffix name (format file)
//Method 1:
Copy the code The code is as follows:
function extend_1( $file_name )
{
$retval = “” ;
$pt = strrpos ( $file_name , “.” );
if ( $ pt ) $retval = substr ( $file_name , $pt +1, strlen ( $file_name ) - $pt );
return ( $retval );
}
//Method 2
Copy code The code is as follows:
function extend_2( $file_name )
{
$extend = pathinfo ( $file_name );
$extend = strtolower ( $extend [ "extension" ]);
return $extend ;
}
//Method 3
Copy the code The code is as follows:
function extend_3( $file_name )
{
$extend = explode ( “.” , $file_name );
$va = count ( $extend )-1;
return $extend [ $ va ]; 🎜> The code is as follows:
function getFileExt( $file_name )
{
while ( $dot = strpos ( $file_name , “.” )) {
$ file_name = substr ($file_name, $dot +1); } return $file_name;
} ?> :PHP pathinfo() function PHP Filesystem function
Definition and usage
pathinfo() function returns file path information in the form of an array.
Syntax
pathinfo(path,options)
Parameters
Description
path
Required. Specifies the path to be checked.
process_sectionsOptional. Specifies the array elements to be returned. The default is all.
Possible values:
PATHINFO_DIRNAME – returns only dirname
PATHINFO_BASENAME – returns only basenamePATHINFO_EXTENSION – returns only extensionDescription
pathinfo() returns an associative array containing path information. Includes the following array elements: [dirname]
[basename]
[extension]
Tips and comments
Comments:
If not all units are required, the pathinfo() function returns a string. Example
Example 1
Copy code The code is as follows:
phpprint_r( pathinfo ( “/testweb/test.txt” ));?>
// Output:
// Array([dirname] => /testweb[basename] => test.txt[ extension] => txt)
Example 2
Copy code
The code is as follows:
// Output:
// test.txt
http://www.bkjia.com/PHPjc/327526.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327526.html
TechArticle
php gets the file suffix name (format file) //Method 1: Copy the code The code is as follows: ?php function extend_1( $file_name ) { $retval = "" ; $pt = strrpos ( $file_name , "." );...