If I have the following HTML code:
<ul>
<li>
<a href="/link1/">link 1</a>
</li>
<li>
<a href="/link2/">link 2</a>
</li>
...
</ul>
How can I use PHP to return an array containing the contents of all the href’s?
ex:
$array[0]="/link1/";
$array[1]="/link2/";
and so on.
You can use
DOMDocumentalong withDOMXpath(plus this reference or this chart) to extract just about anything from the HTML:Change
loadHTML($string)toloadHTMLFile($path_or_url)to load contents from a file.