例如给定 http://www.75271.com/index.html?id=1 返回.html
<?php /** * 给定url,获取文件后缀 * @param string $url * @return string */ function getUrlPostfix ($url) { $url_arr = explode('.', $url); $postfix = $url_arr[count($url_arr) - 1]; $substr = substr($postfix, 0, 3); return $substr; } $url = "http://www.75271.com/index.html?id=1"; $str = getUrlPostfix($url); echo $str . "\n";