获取文件名后缀_PHP教程

WBOY
发布: 2016-07-20 11:14:50
原创
949 人浏览过

1. 写一个函数,尽可能高效的,从一个标准 url 里取出文件的扩展名
例如: http://www.sina.com.cn/abc/de/fg.php?id=1 需要取出 php 或 .php

<?<span php 
</span><span $url</span> = "http://www.sina.com.cn/abc/de/fg.php?id=1 "<span ;
<br />//这个是自己写的
</span><span function</span> getUrl(<span $url</span><span ) {
    </span><span $date</span> = <span explode</span>('?', <span $url</span><span );
    </span><span $date</span> = <span basename</span>(<span $date</span>[0<span ]);
    </span><span $date</span> = <span explode</span>('.', <span $date</span><span );
    </span><span return</span> <span $date</span>[1<span ];
}

</span><span var_dump</span>(getUrl(<span $url</span><span ));

//下面两个是网上弄的
</span><span function</span> getExt(<span $url</span><span ){
   </span><span $arr</span> = <span parse_url</span>(<span $url</span><span );
  
   </span><span $file</span> = <span basename</span>(<span $arr</span>['path'<span ]);
   </span><span $ext</span> = <span explode</span>(".",<span $file</span><span );
   </span><span return</span> <span $ext</span>[1<span ];
}

</span><span var_dump</span>(getExt(<span $url</span><span ));



</span><span function</span> getName(<span $url</span><span ) {

   </span><span $w_param</span> = <span pathinfo</span>(<span $url</span><span );

   </span><span $str</span> = <span $w_param</span>['extension'<span ];

   </span><span list</span>(<span $type</span>, <span $vars</span>) = <span explode</span>('?',<span $str</span><span );

   </span><span return</span> <span $type</span><span ;

}
</span><span echo</span> 'start3'.<span date</span>("Y-m-d H:i:s"<span );
</span>?>
登录后复制

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/440243.htmlTechArticle1. 写一个函数,尽可能高效的,从一个标准 url 里取出文件的扩展名 例如: http://www.sina.com.cn/abc/de/fg.php?id=1 需要取出 php 或 .php ? = "http://ww...
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板