获取方法:1、用“substr(strrchr($url,"."),1)”语句;2、用“substr($url,strrpos($url,'.')+1)”语句;3、用“pathinfo($url,PATHINFO_EXTENSION)”。

本教程操作环境:windows7系统、PHP7.1版、DELL G3电脑
php获取url扩展名的方法
方法1:
<?php
$url="http://localhost/user/order.php";
function get_ext1($url){
return substr(strrchr($url,"."),1);
}
echo get_ext1($url);
?>
立即学习“PHP免费学习笔记(深入)”;
方法2:
<?php
$url="http://localhost/user/order.php";
function get_ext2($url){
$p=pathinfo($url);//Array ( [dirname] => http://localhost/user [basename] => order.php [extension] => php [filename] => order )
return $p['extension'];
}
echo get_ext2($url);
?>方法3:
<?php
$url="http://localhost/user/order.php";
function get_ext3($url){
return substr($url,strrpos($url,'.')+1);
}
echo get_ext3($url);
?>方法4:
<?php
$url="http://localhost/user/order.php";
function get_ext4($url){
$arr=explode('.',$url);
return array_pop($arr);
}
echo get_ext4($url);
?>方法5:
<?php
$url="http://localhost/user/order.php";
function get_ext5($url){
return pathinfo($url,PATHINFO_EXTENSION);
}
echo get_ext5($url);
?>推荐学习:《PHP视频教程》
以上就是php获取url扩展名的几种方法是什么的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号