<?php //获取文件扩展名 $file = 'youkud.com.php'; //方法1 $path_info = pathinfo($file); //print_r($path_info); //echo "<br>"; //echo $path_info['dirname']; //echo "<br>"; //echo $path_info['basename']; echo "<br>"; echo strtolower($path_info['extension']); //方法2 echo "---------------------<br/>"; $p = strrpos($file,'.'); //得到最后一个点的位置 echo strtolower(substr($file,$p+1)); //方法3 echo "---------------------<br/>"; $arr = explode('.',$file); echo strtolower($arr[count($arr)-1]); //方法4 echo "---------------------<br/>"; $arr = explode('.',$file); echo strtolower(end($arr)); //方法5 echo "---------------------<br/>"; preg_match('/\.(\w+)$/',$file,$extend); echo strtolower($extend['1']); //方法6 echo "---------------------<br/>"; //strrchr($file,'.') 最后一次出现的位置开始到最后的字符串 echo strtolower(substr(strrchr($file,'.'),1)); //by http://www.youkud.com ?>