1

我有一个 php 脚本,它使用file_get_contents('http://remote_site.com/page.html'). 我遇到的唯一问题是它仅所有数据都被抓取和处理后才打印数据。脚本正在报废时,有没有办法print 或数据?echo

4

2 回答 2

0

如果您想在读取远程文件时使用(并刷新)缓冲区,我相信您需要从 using 切换file_get_contents到使用f-commands ( fopen, , 等)以便fgets能够处理/flush代码,因为你正在报废。file_get_contents()不支持远程文件的偏移参数,因此您必须等到文件被完整读取才能处理结果。

您必须检查allow_url_fopen您的 php.ini 文件中是否启用了该功能,但您应该能够编写类似这样的内容(从文档修改):

$file = fopen ("http://www.example.com/", "r");
if (!$file) {
    echo "<p>Unable to open remote file.\n";
    exit;
}
ob_start();
while (!feof ($file)) {
    $line = fgets ($file, 1024);
    $buffer = $line;//you can manipulate what goes to the buffer here
    echo $buffer;
    ob_flush();
    flush(); 
}
fclose($file);

你可能需要玩这个,因为我没有测试过,但我认为这是你想要采取的方法。

于 2012-10-08T04:46:08.210 回答
-2

Try

<?php
print '<pre>'.print_r($data, 1).'</pre>';
于 2012-10-08T04:30:58.997 回答