我正在用PHP编写代码来查找给定网页的总大小。但是如果URL指向单个文件资源(如png,gif,txt等文件),那么我将不需要解析传递的URL指向的页面,以查看是否有任何链接到其他资源(如.js,.css等文件)。
答案 0 :(得分:1)
Parhaps解析响应并检查MIME类型。例如,如果您使用的是cURL:
<?php
// Create a curl handle
$ch = curl_init('http://www.yahoo.com/');
// Execute
curl_exec($ch);
// Check if any error occured
if(!curl_errno($ch))
{
$info = curl_getinfo($ch);
echo 'Took ' . $info['total_time'] . ' seconds to send a request to ' . $info['url'] .'<br>';
echo 'Content type:' . $info['content_type'];
// Parse based on content type.
}
// Close handle
curl_close($ch);
?>