我正在用PHP编写代码来找出给定网页的总大小。但是如果URL指向单个文件资源(如png、gif、txt等文件),那么我不需要解析该URL所指向的页面来查看是否有指向其他资源(如.js、.css等文件)的链接。
发布于 2011-08-21 07:22:16
解析响应并检查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);
?>https://stackoverflow.com/questions/7135312
复制相似问题