php: Parse string from html

后端 未结 3 418
借酒劲吻你
借酒劲吻你 2021-01-03 10:13

I have opened an HTML file using

file_get_contents(\'http://www.example.com/file.html\')

and want to parse the line including \"ParseThis\"

3条回答
  •  春和景丽
    2021-01-03 11:05

    Since it is the first h1 tag, getting it should be fairly trivial:

    $doc = new DOMDocument();
    $doc->loadHTML($html);
    $h1 = $doc->getElementsByTagName('h1');
    echo $h1->item(0)->nodeValue;
    

    http://php.net/manual/en/class.domdocument.php

提交回复
热议问题