I have talked about many methods of obtaining file suffixes before. Today we will summarize again about using different functions to obtain them. Friends in need can refer to them.
1. PHP explode function, function usage reference http://www.bKjia.c0m/phper/24/f486bb8b0528a628528530b295e6281b.htm
The code is as follows
代码如下 |
复制代码 |
$pic = 'abc.php';
$pics = explode('.' , $pic);
echo $num = count($pics);
echo ' '.$pics[$num-1];
|
|
Copy code
|
$pic = 'abc.php';
$pics = explode('.' , $pic);
代码如下 |
复制代码 |
foreach ($pics as $value) //2
{
$a = $value;
}
echo $a.' ';
|
echo $num = count($pics);
echo ' '.$pics[$num-1];
代码如下 |
复制代码 |
echo end($pics);
echo ' ';
|
| This way you can output
.php.
The following uses foreach. This function usage http://www.bKjia.c0m/phper/18/foreach-foreach.htm
The code is as follows
Copy code
|
foreach ($pics as $value) //2
{
$a = $value;
}
echo $a.' ';
There is a better function end. I recommend using this function for shortcut end function usage http://www.bKjia.c0m/w3school/php/func_array_end.htm
The code is as follows
|
Copy code
|
|
|