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

时间:2017-07-25 21:27:33

标签: php html parsing file-get-contents

我试图将多个html页面的代码解析为字符串,使其像缓冲区一样,并读取此字符串以查找输入的特定文本,everthing是可以的,唯一的问题,是因为我无法将页面加载到字符串中并在之后阅读。

$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 个答案:

答案 0 :(得分:2)

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

}