Reading part of a remote page in PHP
I have a page at URL http://site.com/params. I want to read only the first n characters from this remote page. Functions like readfile()
, file_get_contents()
and curl
seem to download whole of the pages. Can't figure out how to do this in PHP.
Please help...!
file_get_contents()
may be what you're looking for if the maxlen
parameter is utilized. By default, this function:
//Reads entire file into a string
$wholePage= file_get_contents('http://www.example.com/');
However, the maxlen parameter is the maximum length of data read.
// Read 14 characters starting from the 1st character
$section = file_get_contents('http://www.example.com/', NULL, NULL, 0, 14);
This implies that the entire file is not read, and only maxlen
characters are read, if maxlen
is defined.
你可以尝试通过套接字链接
$handle = fopen("http://domain.com/params", "r");
$buffer = fgets($handle, 100);
echo $buffer;
fclose($handle);
链接地址: http://www.djcxy.com/p/65598.html
上一篇: 在php中从远程服务器获取文件的最可靠方法是什么?
下一篇: 用PHP读取远程页面的一部分