So I wanted to know if there was a way to grab a specific HTML tag’s information using PHP.
Let’s say we had this code:
<ul>
<li>First List</li>
<li>Second List</li>
<li>Third List</li>
</ul>
How could I search the HTML and pull the third list item’s value into a variable? Or is there a way you could pull the entire unordered list into an array?
Has not been tested or compiled, but one way is create a function that utilizes PHP: DOMDocument and its method
getElementsByTagNamewhich returns aPHP: DOMNodeList that you can access the node at a specific index.
If you call
grabAttributes("myfile.html", "li", 2)the variable will be set to"Third List"Or you can make a function to put all the attributes of a given tag into an array.
If you call
putAttributes("myfile.html", "li")it would returnarray("First List", "Second List", "Third List")