如何将多个html页解析成一个字符串?

How to parse multiple html pages into a string?

我试图将多个 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;

}

在这种情况下有人可以帮助我吗?

此致

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

}