獲取文件名的擴展名

文件名類型有:http://localhost/code/loginfile/index.ini.php?username=aaa

              E:\xampp\php/login.php

              login.php

function file_extension($url)
{
	//第一步:判斷是否有問號"?"
	$file="";  //存儲整個文件名稱
	if (strstr($url,"?")){
		list($file)=explode("?", $url);
	}
	else
		$file=$url;
//	echo $file."<br>";
	
	//第二步:獲取文件的名稱
	$pos=strrpos($file, "/")+1;
//	echo $pos."<br>";
	$filename=substr($file,$pos);
//	echo $filename."<br>";
	//第三步:獲取後綴名
	$arr=explode(".", $filename);
	$exname=array_pop($arr);
	echo $exname."<br>";
	
}
file_extension("http://localhost/code/loginfile/index.ini.php?username=aaa");
file_extension("E:\xampp\php/login.php");
file_extension("login.php");
file_extension("http://localhost/code/loginfile/index.ini.php?username=aaa");


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章