标签:
方法一:
function get_ext1($path) { return strrchr($path,‘.‘); } echo get_ext1(__FILE__);
方法二:
function get_ext2($path) { return substr($path,strrpos($path, ‘.‘)); } echo get_ext2(__FILE__);
方法三:
function get_ext3($path) { $result = pathinfo($path); //array(4) { ["dirname"]=> string(26) "D:\wamp\apache\htdocs\test" ["basename"]=> string(10) "demo29.php" ["extension"]=> string(3) "php" ["filename"]=> string(6) "demo29" } return $result[‘extension‘]; } var_dump(get_ext3(__FILE__));
方法四:
function get_ext4($path) { $result = explode(‘.‘, $path); return $result[count($result)-1]; } echo get_ext4(__FILE__);
方法五:
function get_ext5($path) { $pattern = ‘/^[^\.]+\.([\w]+)$/‘; return preg_replace($pattern,‘${1}‘, basename($path)); } echo get_ext5(__FILE__);
标签:
原文地址:http://www.cnblogs.com/lesuso/p/4886230.html