php - Using DOMDocument, is it possible to get all elements that exists within a certain DOM? -
Assume that I have an HTML file with many different elements, suppose I do not already know that it What the HTML looks like
Using PHP's DOMDocument, how can I recycle and modify the all elements? I see that the elementbet tagname gets and the elementbid is found. I want to iterate through all the elements. For example suppose that HTML looks like this (just one example, I really do not know the structure): I want to be able to do some simple DOM modifications (like JavaScript): Then in this example, The resultant HTML would look like: How can I be repeated through all the elements and amend them while flying in the forech-loop? I actually have regex You can pass an asterisk From: Name
$ html = '
$ dom = new DOMDocument (); $ Dom- & gt; loadHTML ($ HTML); // The code below clearly does not work, but shows how I want to get the foreach ($ dom-> GetAllElements $ element) {if (! $ Element- & gt; Hexellale ('Potatoes')) {$ element-> AddClass ('potatoes'); } And ($ element-> removeClass ('potato');}} $ Html = $ dom-> Save HTML ();
$ html = '
* with which all elements return:
foreach ($ dom-> getElementsByTagName ('*') as $ element) {}
The tag's local name (non-namespace) special value tag * matches all tags.
Comments
Post a Comment