How to delete nodes found with xpath-> query from a string that contains an HTML document with PHP -


The use case is quite simple. I would like to search the node in a string (!) Through a xpath statement, which is the basic form of

I know how to find nodes with PHP, it is basically like this: Create a new DOMDocument load HTML (or Load XML) Create a new DOMXpath and then the method "query" or "evaluate". was done.

Although deletion is a difficult part. Someone thinks that you remove nodes with some statements (and finally parentNode-> removechild) and save save the result with just saving the result. Unfortunately, this operation changes "many things" almost every time in the basic HTML string.

So my question is now how can I remove nodes return by xpath-> query ($ query) without saving HTML or saveXML?

Hope it was quite clear: -)

Thanks for watching it!

First of all, make sure that you delete the nodes below and below to ensure that For that you remove the hair nodes before the parent node.

Second, what does "change in so many things" mean? PHP's DOM XML will parse the document in a DOM node tree. Then you work on the tree, and when you do it, it will convert the DOM tree into XML / HTML. You can lose indentation very well, logic can change places and so on. The important thing is that the meaning of the document is exactly the same, i.e. the DOM tree has an accurate XML / HTML presentation.


Comments