There are a lot of advertisements in php to get the file suffix, such as the $ extend [\ "extension \"] After the php function pathinfo gets the result, users who need to know about them can also refer to this document.
Use pathinfo Functions
<? Php
| The Code is as follows: |
Copy code |
Function extend_2 ($ file_name) { $ Extend = pathinfo ($ file_name ); $ Extend = strtolower ($ extend ["extension"]); Return $ extend; } |
Definition and usage
The pathinfo () function returns the file path information in an array.
Syntax
Pathinfo (path, options)
Pathinfo () returns an associated array containing path information.
Includes the following array elements:
[Dirname]
[Basename]
[Extension]
// Obtain the file extension
| The Code is as follows: |
Copy code |
Function getextension ($ filename) { Return substr (strrchr ($ filename, "."), 1 ); } |
Splitting Method
| The Code is as follows: |
Copy code |
Function GetFiletype ($ filename ){ $ Filer = explode (".", $ filename ); $ Count = count ($ filer)-1; Return strtolower (".". $ filer [$ count]); } |
Array_reverse
| The Code is as follows: |
Copy code |
Function getfile ($ filestr ){ // Separate file names with dots into Arrays $ Get = explode ('.', $ filestr ); // Reverse the above Array $ Get = array_reverse ($ get ); // Returns the first value of the inverted array. Return $ get [0]; } $ Filename = getfile('nowamagic.doc '); Echo $ filename; |
Array_reverse
(PHP 4 and PHP 5)
Array_reverse-returns an array whose content order is reversed.
Description
Array array_reverse (array $ array [, Boolean $ preserve_keys = false])
Use a command to input an array and return a new array to reverse the content.