From a file_get_contents
I get the HTML code of a url.
$html = file_get_contents($url);
Now I would like to capture the href
link.
The HTML code is:
<li class="four-column mosaicElement">
<a href="https://example.com" title="Lorem ipsum">
...
</a>
</li>
<li class="four-column mosaicElement">
<a href="https://example.org" title="Lorem ipsum">
...
</a>
</li>
So I'm using this:
preg_match_all('/class=\"four-column mosaicElement\"><a href=\"(.+?)\" title=\"(.+?)"/m', $html, $urls, PREG_SET_ORDER, 0);
foreach ($urls as $key => $url) {
echo $url[1];
}
How do I solve this problem?