多谢楼上的仁兄! 我要用file读取网页内容,fopen()不行吧!请您继续赐教!多谢!
解决方案 »
- 18℃~8℃用正则提取出最低温度并转换成整型应该???
- PHP自动登录新浪微博 出现问题 CURL ERROR: malformed
- unexpected T_VARIABLE, expecting ',' or ';' php
- 为什么在FF下显示就是乱码了??
- eclipsePHP studio运行时提示:启动期间发生了内部错误。请问怎么回事?
- 关于PHP5新特性的一些疑问
- 求纯英文的日历(时间选择)控件
- 怎么把2006-05-14 23:59:59转化为Unix 时间戳,在线等
- 请问关于set names 和set_charset
- 关于session的warnings
- 请问php代码中何时该用双引号,何时不该用
- 怎么解决这种错误?open_basedir restriction in effect
file('http://localhost/页面名.php');
thisky(···Cos.X···)
keaizhong(可爱钟)(温州的PHPER)(19801010)
xuzuning(唠叨)他没有错误信息,就是没有反映了!一直等到超时!我测试一个简单的代码,如下:<?PHP
//调用index2.php文件,显示aaaaaaaaaa 和 cccccccc中间的东西。
$strSoHuGNXW = file("index2.php");
$SoHucount = count($strSoHuGNXW);
for ($i=0;$i<$SoHucount;$i++){
$fileSoHuGNXW .= $strSoHuGNXW[$i];
$SoHuGNGD = explode("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",$fileSoHuGNXW);
$SoHuGNGD = explode("ccccccccccccccccccccccccccccccccc",$SoHuGNGD[1]);
$SoHuGNGD = $SoHuGNGD[0];
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head><?php echo $SoHuGNGD; ?><body>
</body>
</html>因为index2.php ,aaaa和cccc,中间是bbbbbb,就显示bbbbb了,可是传到服务器上就没有反映了,一直到超时!
<?php
$r=new HTTPRequest("http://my.haokan123.com/Diary/Html/HaoKan123_V2_44481.Html");
$htm=$r->DownloadToString();
echo $htm;
class HTTPRequest
{
/*
获取网页
*/
var $_fp; // HTTP socket
var $_url; // full URL
var $_host; // HTTP host
var $_protocol; // protocol (HTTP/HTTPS)
var $_uri; // request URI
var $_port; // port
// scan url
function _scan_url()
{
$req = $this->_url;
$pos = strpos($req, '://');
$this->_protocol = strtolower(substr($req, 0, $pos));
$req = substr($req, $pos+3);
$pos = strpos($req, '/');
if($pos === false)
$pos = strlen($req);
$host = substr($req, 0, $pos);
if(strpos($host, ':') !== false)
{
list($this->_host, $this->_port) = explode(':', $host);
}
else
{
$this->_host = $host;
$this->_port = ($this->_protocol == 'https') ? 443 : 80;
}
$this->_uri = substr($req, $pos);
if($this->_uri == '')
$this->_uri = '/';
}
// constructor
function HTTPRequest($url)
{
$this->_url = $url;
$this->_scan_url();
}
// download URL to string
function DownloadToString()
{
$crlf = "\r\n";
$response="";
// generate request
$req = 'GET ' . $this->_uri . ' HTTP/1.0' . $crlf
. 'Host: ' . $this->_host . $crlf
. $crlf;
// fetch
$this->_fp = fsockopen(($this->_protocol == 'https' ? 'ssl://' : '') . $this->_host, $this->_port);
fwrite($this->_fp, $req);
while(is_resource($this->_fp) && $this->_fp && !feof($this->_fp))
$response .= fread($this->_fp, 1024);
fclose($this->_fp);
// split header and body
$pos = strpos($response, $crlf . $crlf);
if($pos === false)
return($response);
$header = substr($response, 0, $pos);
$body = substr($response, $pos + 2 * strlen($crlf));
// parse headers
$headers = array();
$lines = explode($crlf, $header);
foreach($lines as $line)
if(($pos = strpos($line, ':')) !== false)
$headers[strtolower(trim(substr($line, 0, $pos)))] = trim(substr($line, $pos+1));
// redirection?
if(isset($headers['location']))
{
$http = new HTTPRequest($headers['location']);
return($http->DownloadToString($http));
}
else
{
return($body);
}
}
}
?>这个代码在服务器上就可以调用外部文件了!!!! 到底为什么呢? 多谢热心的各位仁兄!!多谢!!!
<?php
echo ini_get("disable_functions");
print_r(ini_get_all());
?>
</pre>结果中搜索disable_functions
2006-5-18 16:27:55
发的测试程序如果运行有问题
那就是file() disable了换用其他的函数
file_get_contents() / fopen()
fopen() eg:
if(!$fh=fopen($url,"r")){
die("could not open $url");
}
while(!feof($fh)){
$line.=fgets($fh,4096);
}
fclose($fh);