Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
$path = 'abc.jpeg'; $info = pathinfo($path,PATHINFO_EXTENSION); echo $info['extension'];
出于某种原因,这将返回“j”,而不是“jpeg”
在调用 pathinfo() 之前我应该做些什么?
如果将第二个参数传递给 pathinfo,则它不会返回数组。
你应该回显 $info。
从文档(realpath):
如果使用选项,如果不是所有元素都被请求,此函数将返回一个字符串。
访问$info['extension'];恰好是访问字符串数组的第一个字符。
$info['extension'];
感谢蒂姆库珀的评论。(int)'extension'评估为 0。在“字符串访问和按字符修改”部分中有关字符串类型的文档中,概述了如何将字符串作为数组访问,在它提到的注释中:
(int)'extension'
非整数类型转换为整数。