如何检查给定的 URL 是指网页还是原始文件?现在,我检查整个文件是否包含字符串<html>
,但这既不有效也不可靠。
$content = file_get_contents($url);
if($content)
{
// is directory
if(strrpos($content, "<html>"))
{
echo $url . " is a folder." . "<br>";
}
else // use raw file...
}
else echo $url . " was not found." . "<br>";