如果我想使用 pathinfo 函数获取 URL 的扩展名,我这样做:
<?php
$path_parts = pathinfo($url);
echo $path_parts["extension"];
?>
令我惊讶的是 Apache 显示以下通知:
Notice: Undefined index: extension in ...
我该如何处理?谢谢。
如果您只想获得扩展名,请使用:
$extension = pathinfo($url, PATHINFO_EXTENSION);
echo $extension;
function getExtension($url)
{
$url = explode('.',$url);
return $url[count($url)-1];
}
您可以使用此手动功能来检索它。
I'm a bit late to the party but you'd get an undefined index while doing an echo $path_parts["extension"]
if the target is a directory.