Skip to content
Advertisement

How to delete every element of specific type in php? [closed]

Hey so i have a use of a php function that would delete every element of specific type in php. More specifically i want to delete all the labels on my website, e.g:

JavaScript

Any help is appreciated.

Advertisement

Answer

A couple of ways:

With XPath:

JavaScript

Result

JavaScript

With getElementsByTagName

Due to it being a live document you convert the iterator to an array with iterator_to_array

JavaScript

Result

JavaScript

See it online: https://3v4l.org/WJpqk

You could extend DOMDocument if you want to add your own methods

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement