views:

70

answers:

1
+1  A: 

I don't have simple_html_dom installed on my machine or dev server so I can't test, but from the looks of it, setting $span_tag->outertext will create new span objects inside the outer span, so the old references will no longer exist in $HTML. Going from innermost to outer should fix it since the references would be kept intact.

EDIT: In your second edit, you are finding the newly-created spans every time you do a replacement, which is why it works.

Max Shawabkeh