PHP头条
热点:

几种获取路径的后缀名方法-PHP源码


跳至

$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 "
";
echo get_ext2($file);
echo "
";
echo get_ext3($file);
echo "
";
echo get_ext4($file);
echo "
";
echo get_ext5($file);
echo "
";
echo (preg_replace('/.*\.(.*[^\.].*)*/iU','\\1',$file));

www.phpzy.comtrue/php/34179.htmlTechArticle几种获取路径的后缀名方法-PHP源码 跳至 $file = "http://www.phpzixue.cn/images/phpzixue.gif"; function get_ext1($file){ return substr(strrchr($file, .), 1); //strrchr取得字元最后一次出现处到结尾的字符串} func...

相关文章

PHP之友评论

今天推荐