2012-10-08 28 views
1

我有一個PHP腳本,從網站使用file_get_contents('http://remote_site.com/page.html')刮傷數據。我遇到的唯一問題是它在之後僅打印的數據,並且所有數據都被抓取和處理。有沒有辦法通過printecho這個腳本所報廢的數據?顯示數據,因爲它擦傷在php

+0

查看手冊中的[flush()](http://php.net/manual/en/function.flush.php)。不要拿出許可證。 – 2012-10-08 04:23:44

+0

你現在怎麼報廢頁面? 'cURL'? 'file_get_contents'?向我們展示一些代碼 –

+0

將看着flush()感謝Dagon。我是一個使用file_get_contents @Ben D的廢品 – user1050982

回答

-2

嘗試

<?php 
print '<pre>'.print_r($data, 1).'</pre>'; 
0

如果你想與其合作(和沖洗)緩衝作爲你讀遠程文件,我相信,你將需要使用file_get_contents使用f - 命令切換(fopen,fgets等),以便能夠處理/ flush代碼。 file_get_contents() does not support the offset parameter for remote files,因此您必須等到文件全部讀完後才能處理結果。

你必須檢查allow_url_fopen你的php.ini文件中啓用,但你應該能夠編寫這樣的事情(從the documentation修改):

$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); 

您可能需要玩這一點,因爲我沒有測試過,但我認爲這是你想要採取的方法。

相關問題