【发布时间】:2016-07-05 13:08:22
【问题描述】:
我想获取我拥有它们的所有页面内容 url
我为获取https://fonts.googleapis.com/css?family=Open+Sans的内容编写了以下php代码
function curl_file_get_content($url){
$agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
$ch=curl_init();
curl_setopt_array($ch, [
CURLOPT_URL=>$url,
CURLOPT_USERAGENT=>$agent,
CURLOPT_RETURNTRANSFER=>1,
CURLOPT_TIMEOUT=>5,
CURLOPT_VERBOSE=>0,
CURLOPT_SSLVERSION=>3,
CURLOPT_SSL_VERIFYPEER=>0,
CURLOPT_SSL_VERIFYHOST=>0,
]);
$page=curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if($httpcode>=200 && $httpcode<300) return $page;
else return false;
}
if($content=curl_file_get_content("https://fonts.googleapis.com/css?family=Open+Sans")){
echo $content;
}else{
echo "the Website is DOWN" ;
}
输出如下代码
@font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: 400;
src: url(https://fonts.gstatic.com/s/opensans/v13/cJZKeOuBrn4kERxqtaUH3fY6323mHUZFJMgTvxaG2iE.eot);
}
如果您查看 url https://fonts.googleapis.com/css?family=Open+Sans,您会注意到此页面的内容,并且我的代码输出是不同的,并且我的代码输出是该页面的一部分
但此代码可正常用于获取本地主机文件的内容
有什么问题? 我可以得到这个页面的完整内容吗?
【问题讨论】:
标签: php html curl load php-curl