2017-07-25 27 views
2

我想解析多個html頁面的代碼到一個字符串,使得像一個緩衝區,並閱讀此字符串,以便找到一個特定的文本輸入,everthing是好的,唯一的問題,是我無法將頁面加載到字符串中並讀取之後。如何將多個html頁面解析爲字符串?

$url = 'http://www.test.com/'; 
$start = 0; 
$end = 1120; 

$counter = $start; 
while ($counter <= $end) { 

    /*** a link to search - add the counter value and html to the end of url ***/ 
    $link = "$url$counter.html"; 
    /*** get the links ***/ 
     $data = file_get_contents($link); 
     $data = $data.$data; 
//  echo $data; 

    $counter = $counter + 15; 

} 

有人能幫助我在這種情況下?

問候

+1

說明什麼? –

+1

你有沒有做任何調試? 'file_get_contents'的結果是什麼? –

+0

爲什麼你正試圖從多個頁面解析DOM到一個字符串?像你想要解決什麼樣的問題?當然有更好的方法來做你想做的事情。 –

回答

1
$url = 'http://www.test.com/'; 
$start = 0; 
$end = 1120; 
$counter = $start; 
$data=""; 
while ($counter <= $end) { 
    $link = "$url$counter.html"; 
    $res = file_get_contents($link); 
    If ($res!==false){ 
     $data .=$res; 
    } 
    $counter = $counter + 15; 

} 
+0

對問題和解決方案的一點解釋會使這個很好而且完整。 – showdev

+0

這工作,但執行200頁緩衝區時,字符串顯示未定義的錯誤,也許字符串保持超大? –

+1

不要認爲這樣的字符串大小限制大約是2GB –