Php method for getting the file suffix
$ Pic = 'abc.3434.342.12123.123.exe ';
- $ Pics = explode ('.', $ pic );
/* Obtain the total number of arrays and then take the last one */
- Echo $ num = count ($ pics );
- Echo'
'. $ Pics [$ num-1];
/* Traverse the array and obtain the last element */
- Foreach ($ pics as $ value) // 2
- {
- $ A = $ value;
- }
- Echo $ .'
';
- /* Directly output the last element of the array */
- Echo end ($ pics );
- Echo'
';
- /* Pay attention to the difference between the last element of a single-output array and end */
- // Echo array_pop ($ pics );
- /* Sort the array in reverse order based on the key value, and then output the first element */
- Krsort ($ pics );
- Echo array_shift ($ pics );
- Echo'
';
/* The value corresponding to the extension index returned by the pathinfo () function */
- $ Res = pathinfo ($ pic); // 5
- Var_dump ($ res );
- Echo $ res ['extension'].'
';
/* Extract the string and take the last three digits */
- Echo substr ($ pic,-3, 3 );
- ?>
|