The first type of method is done using arrays. First cut the file name to a group, and then find a way to get the last element of the array OK. The second type of method is done through the processing of strings, and another method is to use the PathInfo () function.
Copy Code code as follows:
$pic = ' Abc.3434.342.12123.123.exe ';
$pics = Explode ('. ', $pic);
/* Get the total number of arrays, and then take the last one * *
echo $num = count ($pics);
Echo ' <br> '. $pics [$num-1];
/* Traverse Array to get the last element * *
foreach ($pics as $value)//2
{
$a = $value;
}
echo $a. ' <br> ';
/* Direct output array last element * *
Echo End ($pics);
Echo ' <br> ';
/* The last element of the group, note the difference with end () * *
echo Array_pop ($pics);
/* First order the array according to the key value, then the first element.
Krsort ($pics);
echo Array_shift ($pics);
Echo ' <br> ';
/*pathinfo () function returns the value of the extension index corresponding to the value * *
$res = PathInfo ($pic); 5
Var_dump ($res);
echo $res [' extension ']. <br> ';
/* String intercept, take the last three bits can be * *
Echo substr ($pic,-3, 3);
We can see that a problem has n a variety of solutions, in the process of doing the same, the solution is always there, for some novice, must adhere to, so as to learn good PHP!