php获取url中文件扩展名

tech2026-10-09  1

// 尽可能高效从一个标准url中获取文件的扩展名 // 例如 http://www.daiyuanpei.com/dai.php?id=1 取出 .php 或者 php $url = 'http://www.daiyuanpei.com/dai.php?id=1'; // php function getExt($url){ $arr = parse_url($url); $file = basename($arr['path']); $ext = explode('.', $file); return $ext[1]; } // php function getExt2($url) { $url = basename($url); $pos1 = strpos($url, '.'); $pos2 = strpos($url, '?'); if(strstr($url, '?')){ return substr($url, $pos1+1, $pos2-$pos1-1); }else{ return substr($url, $pos1); } }

 

最新回复(0)