Home  >  Article  >  Backend Development  >  Multiple ways to get file extensions in php_PHP tutorial

Multiple ways to get file extensions in php_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 16:59:44879browse

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

This way you can output .php.
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 '
';

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
echo end($pics); echo '
'; Other access methods can be determined when the file is uploaded, but that requires the file to be uploaded and we cannot use $_FILES to operate. http://www.bkjia.com/PHPjc/631289.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631289.htmlTechArticleI have talked about many methods of obtaining file extensions before. Today we will once again summarize the methods of using different types of file extensions. Function to obtain, friends in need can refer to one, php...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn