php内置函数getimagesize可以取得图片的类型,但是自己写了一个获取图片后缀名的方法。
- <?php
- class Suffix{
- public $str;
- public function __construct($string){
- $this->str = $string;
- }
- public function getSuffix(){
- $pos = strpos($this->str,'.',1);
- $suffix = substr($this->str,$pos+1);
- return $suffix;
- }
- }
- $str = new Suffix('45.17226c-jw1d.r52jjo4ppj.jpg');
- echo $str->getSuffix(); //result:jpg
- ?>