几种获取路径的后缀名方法
<无详细内容>
$file = "http://www.phpzixue.cn/images/phpzixue.gif";
function get_ext1($file)
{
return substr(strrchr($file, '.'), 1); //strrchr取得字元最后一次出现处到结尾的字符串
}
function get_ext2($file)
{
return pathinfo($file, PATHINFO_EXTENSION);
//pathinfo以数组的形式返回文件路径的信息。PATHINFO_DIRNAME - 只返回 dirname
//PATHINFO_BASENAME - 只返回 basename
//PATHINFO_EXTENSION - 只返回 extension
}
function get_ext3($file)
{
return substr($file, strrpos($file, '.')+1); //strrpos找出字元最后一次出现的位置
}
function get_ext4($file)
{
return array_pop(explode('.', $file));
//array_pop取得数组的最后一个元素
//explode切开字符串传回一个字符串的数组
}
function get_ext5($file)
{
$tok = strtok($file, '.'); //strtok切开字符串
while($tok !== false)
{
$return = $tok;
$tok = strtok('.');
}
return $return;
}
echo get_ext1($file);
echo "<br />";
echo get_ext2($file);
echo "<br />";
echo get_ext3($file);
echo "<br />";
echo get_ext4($file);
echo "<br />";
echo get_ext5($file);
echo "<br />";
echo (preg_replace('/.*\.(.*[^\.].*)*/iU','\\1',$file));
- 上一篇:一段简单又实用的PHP获取RSS订阅代码
- 下一篇:先识别标签后计算的模板思路
精彩图集
精彩文章






