0

I'm trying to parse through a page using PHP's Simple HTML DOM script, but unable to make the removals persist.

Firstly I want to clean up a few unwanted items. I've gone ahead and removed those outertexts by = ''.

However, whenever I run the next find, they show up again.

By visiting this Stack Overflow question, I noticed that I should be saving back to the variable.

I tried $html->save();, but it throws up an error:

Fatal error: Uncaught Error: Call to undefined method simple_html_dom_node::save() in /var/www/public/...

If I remove this save(), then when I run the next foreach, the div#bar that I removed still shows up.

Any help would be appreciated!

foreach($html->find('div#foo') as $bullets) {

    $bullets->find('div#bar',0)->outertext = '';
    $bullets->save(); //this statement gives a fatal error

    foreach($bullets->find('span.a-list-item') as $bulletpoints) {
        echo "<br>".$bulletpoints."<br>";
    }
Patrick Q
  • 6,373
  • 2
  • 25
  • 34
Varun Jain
  • 21
  • 1
  • 4
  • Where does the save function come from? It's not in [simple_html_dom](http://simplehtmldom.sourceforge.net/manual.htm). – Ibu Feb 11 '19 at 19:13
  • Looking at simple_html_dom, it seems to be there: ` // save dom as string function save($filepath = '') { $ret = $this->root->innertext(); if ($filepath !== '') { file_put_contents($filepath, $ret, LOCK_EX); } return $ret; }` – Varun Jain Feb 12 '19 at 03:12

0 Answers0