=== 方法一 ===
function grabContentByUrl($url){
$curl = curl_init($url);
$header_string_1 = "Content-Type: application/html";
$header_string_2 = "Accept: application/html";
curl_setopt($curl, CURLOPT_HTTPHEADER, array($header_string_1, $header_string_2));
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
if (curl_errno($curl)) {
return false;
} else {
curl_close($curl);
}
return $response;
}if($pagecontent = grabContentByUrl('http://www.google.com')){
echo $pagecontent;
}
function grabContentByUrl($url){
$curl = curl_init($url);
$header_string_1 = "Content-Type: application/html";
$header_string_2 = "Accept: application/html";
curl_setopt($curl, CURLOPT_HTTPHEADER, array($header_string_1, $header_string_2));
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
if (curl_errno($curl)) {
return false;
} else {
curl_close($curl);
}
return $response;
}if($pagecontent = grabContentByUrl('http://www.google.com')){
echo $pagecontent;
}
解决方案 »
- 控制器和视图之间传参时字符串前面莫名其妙多了“77u/”字符
- PHP 判断连续号问题
- 请高手来帮我解释下代码!!!多谢!!
- 10人喝酒隔两个人开始喝酒直到每个人都有喝过为止,输出喝酒的顺序
- $sql = "SELECT * FROM through TT,train WHERE TT.TrainNum = train.TrainNum AND EX
- 如果我用的是access数据库,那么该怎样利用php搜索数据库(连接?打开?修改?显示?)
- 如何实现这效果?
- 我用GD绘制的图形,为什么要刷新一次以后,才能得到正确显示?在线求救
- 我是一个地地道道的初学者,首先请各位大虾告诉我怎么配置 php 环境?谢谢大虾们了
- Apache能不能支持中文文件名
- 有没有更好的获取页面提交的参数
- 请问作过php生成excel的朋友一个问题,关于数值型数据的
function grabContentByUrl($url){
return file_get_contents($url);
}echo grabContentByUrl('http://www.google.com');
function grabContentByUrl($url){
return file_get_contents($url);
}echo grabContentByUrl('http://www.google.com');
<?php
$messageurl="http://www.google.com";
if ($messageurl."" <> "") {
echo getURLContent($messageurl);
}
function getURLContent($sURL)
{
$pURL=parse_url($sURL); $pScheme = $pURL["scheme"];
$pServer = $pURL["host"];
$pPort = ($pURL["port"]=="")?80:$pURL["port"];
$pPath = $pURL["path"];
$pPath .= ($pURL["query"]=="")?"":"?".$pURL["query"];
$fp = fsockopen($pServer,80,$errNo,$errStr,30); if (!$fp) {
return ""; } else {
$out = "GET ". '/'.$pPath." HTTP/1.0\r\n"; // $out = "GET ".$pServer .$pPath." HTTP/1.0\r\n";
$out .= "Accept: */*\r\n";
$out .= "Host: ".$pServer."\r\n";
$out .= "Connection: Close\r\n\r\n"; fwrite($fp, $out);
$retContent="";
while (!feof($fp)) {
$retContent.=fgets($fp, 4096);
}
fclose($fp);
return $retContent;
}
} ?> 查了一下http协议出错在于请求资源或url不对要么给url,要么指定/根域
$out = "GET ". '/'.$pPath." HTTP/1.0\r\n"; //或$out = "GET ".$pServer .$pPath." HTTP/1.0\r\n";
$out .= "Accept: */*\r\n"; //