simple_html_dom does not store changes

19 Views Asked by At

I need to execute some consecutive actions using simple_html_dom, that seems not working, without saving the results of the previous action. So let's say this is the first action:

$html = str_get_html('<span class="a">a</span>');

if($elem = $html->find('.a', 0))
{
    $elem->innertext = '<span class="b">b</span>';
}

This works fine, and now the text content of $html is <span class="a"><span class="b">b</span></span>. Now I execute the next action, that is:

if($span = $html->find('.b', 0))
{
    $span->innertext = 'c';
}

This does not work, unless I save before the results of the first action, writing:

$html = str_get_html($html->save());

But doing that more times, slows the execution time very much.

I also tried to replace the first action with the following code:

if($elem = $html->find('.a', 0))
{
    $span = $html->createElement('span', 'b');
    $span->addClass('b');
    $elem->appendChild($span);
}

But the second action still does not work. Is there a solution?

Thanks

0

There are 0 best solutions below