How to get a div via PHP?

前端 未结 3 1999
没有蜡笔的小新
没有蜡笔的小新 2021-02-06 17:14

I get a page using file_get_contents from a remote server, but I want to filter that page and get a DIV from it that has class \"text\" using PHP. I started with

3条回答
  •  Happy的楠姐
    2021-02-06 17:47

    you can use simple_html_dom like here simple_html_dom doc

    or use my code like here :

    include "simple_html_dom.php";
    $html = new simple_html_dom();
    $html->load_file('www.yoursite.com');
    $con_div = $html->find('div',0);//get value plaintext each html
    

    echo the $con_div in plaintext..

    $con_div->plaintext;
    

    it's mean you will find the first div in array ('div',0) and show it in plaintext.. i hope it help you :cheer

提交回复
热议问题