3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html=<<<HTML <h1><a href="http://www.website.com/article/slug-that-has-undetermined-amount-of-hyphens/12345">Whatever</a></h1> <p>Here is a url as plain text: http://www.website.com/article/sluggy-slug</p> <div>Here is a qualifying link: <a href="http://www.website.com/article/slugger-sluggington-jr/666">Whatever</a></div> HTML; $dom = new DomDocument(); $dom->loadHTML($html); foreach ($dom->getElementsByTagName('a') as $item) { $output[] = $item->getAttribute('href'); } var_export($output);

preferences:
52.58 ms | 408 KiB | 6 Q