php获取url扩展名的几种方法是什么

获取方法: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);
?>

1.png

方法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教程

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...