The first class of methods is done using arrays. First cut the file name into the array, and then find a way to get the last element of the list is OK. The second class of methods is done through the processing of strings, and one method is to use the PathInfo () function.
Copy the Code code as follows:
$pic = ' Abc.3434.342.12123.123.exe ';
$pics = Explode ('. ', $pic);
/* Get the total number of arrays and take the last one */
echo $num = count ($pics);
Echo '
'. $pics [$num-1];
/* Iterate through the array to get the last element */
foreach ($pics as $value)//2
{
$a = $value;
}
echo $a. '
';
/* Directly output the last element of the array */
Echo End ($pics);
Echo '
';
/* The last element of a single array, note the difference from end () */
echo Array_pop ($pics);
/* First arrange the array in reverse order of key values and then single out the first element */
Krsort ($pics);
echo Array_shift ($pics);
Echo '
';
/*pathinfo () function returns the value of the extension index of the value */
$res = PathInfo ($pic); 5
Var_dump ($res);
echo $res [' extension ']. '
';
/* String intercept, take the last three bits */
Echo substr ($pic,-3, 3);
You can see a problem has n many solutions, in the process of doing the same time, the solution is always there, for some novice, must adhere to, so that the PHP learning good!
The above describes the dont stop til you get enough php to get the file suffix name? , including dont stop til you get enough content, want to be interested in PHP tutorial friends helpful.