首頁  >  文章  >  後端開發  >  php獲取url擴展名的幾種方法是什麼

php獲取url擴展名的幾種方法是什麼

青灯夜游
青灯夜游原創
2022-02-10 15:55:413086瀏覽

取得方法:1、用「substr(strrchr($url,"."),1)」語句;2、用「substr($url,strrpos($url,'.') 1) 」語句;3、用「pathinfo($url,PATHINFO_EXTENSION)」。

php獲取url擴展名的幾種方法是什麼

本教學操作環境: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獲取url擴展名的幾種方法是什麼

##方法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[&#39;extension&#39;];
}
echo get_ext2($url);
?>

方法3:

<?php
$url="http://localhost/user/order.php";
function get_ext3($url){
	return substr($url,strrpos($url,&#39;.&#39;)+1);
}
echo get_ext3($url);
?>

方法4:

<?php
$url="http://localhost/user/order.php";
function get_ext4($url){
	$arr=explode(&#39;.&#39;,$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中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn