How to get the file name suffix with php_PHP tutorial

WBOY
Release: 2016-07-21 15:07:50
Original
1094 people have browsed it

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)

ParametersDescription
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 basename
PATHINFO_EXTENSION – returns only extension

Description

pathinfo() returns an associative array containing path information.
Includes the following array elements:
[dirname]
[basename]
[extension]

Tips and commentsComments:
If not all units are required, the pathinfo() function returns a string.
Example

Example 1

Copy code

The code is as follows:



// 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.html
www.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 , "." );...


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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!