A line of code in php gets the file suffix. In php, a line of code is used to obtain the file suffix. in php, a line of code is used to obtain the file suffix. many functions are required. we are a bit like functions in asp, let's take a look at the php code to get the file suffix.
In php, the method for getting the file suffix through a line of code should be combined with a lot of functions. this is a bit like a function in asp. let's take a look at it.
Instance:
| The code is as follows: |
|
|
$ Filename = 'd:/wamp/www/sparkphp/rar ';
$ Rs = strtolower (trim (substr (strrchr ($ filename, "."), 1 ))); |
Details:
The strrchr () function is used to locate the last occurrence position of a string in another string and return all characters from this position to the end of the string;
The substr () function is a part of the returned string. 1 indicates the first reading of the string subscript. Until the end;
The trim () function removes spaces before and after the string;
The strtolower () function converts a string to lowercase.
Additional methods
| The code is as follows: |
|
|
// Method 1:
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
Function extend_2 ($ file_name)
{
$ Extend = pathinfo ($ file_name );
$ Extend = strtolower ($ extend ["extension"]);
Return $ extend;
}
// Method 3
Function extend_3 ($ file_name)
{
$ Extend = explode (".", $ file_name );
$ Va = count ($ extend)-1;
Return $ extend [$ va];
}
?> |
The method for getting the file suffix through a line of code in php should be combined with a lot of functions. this is a bit like a function in asp. let's take a look at it now...