$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));
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号