PHP Simple HTML DOM Parser find string

前端 未结 4 780
心在旅途
心在旅途 2020-12-31 18:52

I am using PHP simple DOM parser but it does not seem to have the functionality to search for text. I need to search for a string and find the parent id for it. Essentially

4条回答
  •  没有蜡笔的小新
    2020-12-31 19:26

    $html = file_get_html('http://www.google.com/');
    
    $eles = $html->find('*');
    foreach($eles as $e) {
        if(strpos($e->innertext, 'theString') !== false) {
            echo $e->id;
        }
    }
    

    http://simplehtmldom.sourceforge.net/manual.htm

提交回复
热议问题