繁体   English   中英

阅读PHP中的远程页面的一部分

[英]Reading part of a remote page in PHP

我在URL http://site.com/params上有一个页面 我只想从此远程页面读取前n个字符 诸如readfile()file_get_contents()curl似乎可以下载整个页面。 无法弄清楚如何在PHP中执行此操作。

请帮忙...!

如果使用maxlen参数, file_get_contents()可能就是您要寻找的东西。 默认情况下,此功能:

//Reads entire file into a string
$wholePage= file_get_contents('http://www.example.com/');

但是, maxlen参数是读取最大数据长度

// Read 14 characters starting from the 1st character
$section = file_get_contents('http://www.example.com/', NULL, NULL, 0, 14);

这意味着,整个文件无法读取,只有maxlen字符被读取,如果maxlen定义。

您可以尝试通过套接字链接进行

$handle = fopen("http://domain.com/params", "r");
$buffer = fgets($handle, 100);
echo $buffer;
fclose($handle);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM