php获取url后缀名

  • 黄楚恒
  • 2017-06-29 15:44:01
  • PHP
  • php
<?php
	function getExt($url){
		$arr = parse_url($url);//parse_url解析一个 URL 并返回一个关联数组,包含在 URL 中出现的各种组成部分
	    //'scheme' => string 'http' (length=4)
	    //'host' => string 'www.sina.com.cn' (length=15)
	    //'path' => string '/abc/de/fg.php' (length=14)
	    //'query' => string 'id=1' (length=4)	
		$file = basename($arr['path']);// basename函数返回路径中的文件名部分
		$ext = explode('.',$file);
		return $ext[count($ext)-1];
	}
	print(getExt('http://www.sina.com.cn/abc/de/fg.html.php?id=1'));

Copyright © 2016-2019 709173702@qq.com 版权所有  ICP证粤ICP备16117826号-1
联系邮箱:709173702@qq.com