PHP中是否有任何标准函数只能从相应的文件路径中查找图像的扩展名?
例如,如果我的图像路径类似于'/testdir/dir2/image.gif'那么该函数应返回'gif'.
谢谢
fab*_*rik 45
$ext = pathinfo('/testdir/dir2/image.gif', PATHINFO_EXTENSION); //$ext will be gif
Run Code Online (Sandbox Code Playgroud)
更新:我看到很多downvotes.我的方法有什么问题?请告诉我.
小智 5
我有第一个答案的问题和锚定前的网址.google.com/image.jpg#anchor
更好的解决
$filename_from_url = parse_url($url);
$ext = pathinfo($filename_from_url['path'], PATHINFO_EXTENSION);
Run Code Online (Sandbox Code Playgroud)