3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<HTML <ul class="list-unstyled"> <li> <svg role="icon" class="svg-icon iconLocation" width="18" height="18" viewBox="0 0 18 18"><path d="M8.1 17.698S2 9.906 2 6.382C2 2.857 4.91 0 8.5 0S15 2.857 15 6.382c0 3.524-6.098 11.313-6.098 11.313-.221.292-.58.292-.801.003zm.4-8.448a2.75 2.75 0 1 0 0-5.5 2.75 2.75 0 0 0 0 5.5z"/></svg> NULL </li> <li> <svg role="icon" class="svg-icon iconTwitter" width="18" height="18" viewBox="0 0 18 18"><path fill="#2AA3EF" d="M17 4.038a6.62 6.62 0 0 1-1.885.517 3.299 3.299 0 0 0 1.443-1.816c-.634.37-1.337.64-2.085.79a3.282 3.282 0 0 0-5.593 2.99 9.307 9.307 0 0 1-6.766-3.42A3.222 3.222 0 0 0 1.67 4.75c0 1.14.58 2.143 1.46 2.732a3.278 3.278 0 0 1-1.487-.41v.04c0 1.59 1.13 2.918 2.633 3.22a3.336 3.336 0 0 1-1.475.056 3.29 3.29 0 0 0 3.07 2.28 6.578 6.578 0 0 1-4.85 1.359 9.332 9.332 0 0 0 5.04 1.474c6.04 0 9.34-5 9.34-9.33 0-.14 0-.28-.01-.42a6.63 6.63 0 0 0 1.64-1.7L17 4.038z"/></svg> <a href="https://twitter.com/PHPeeHaa" rel="me" class="url">PHPeeHaa</a> </li> <li> <svg role="icon" class="svg-icon iconGitHub" width="18" height="18" viewBox="0 0 18 18"><path d="M9 1C4.58 1 1 4.58 1 9c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 17 9c0-4.42-3.58-8-8-8z"/></svg> <a href="https://github.com/PeeHaa" rel="me" class="url">PeeHaa</a> </li> <li> <svg role="icon" class="svg-icon iconLink" width="18" height="18" viewBox="0 0 18 18"><path d="M2.9 9c0-1.16.94-2.1 2.1-2.1h3V5H5C2.79 5 1 6.79 1 9s1.79 4 4 4h3v-1.9H5A2.1 2.1 0 0 1 2.9 9zM13 5h-3v1.9h3a2.1 2.1 0 1 1 0 4.2h-3V13h3c2.21 0 4-1.79 4-4s-1.79-4-4-4zm-7 5h6V8H6v2z"/></svg> <a href="http://pieterhordijk.com" rel="me noreferrer" class="url">pieterhordijk.com</a> </li> <li> <svg role="icon" class="svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 1 1 3.732 6.768l1.463-1.463A6 6 0 1 0 5 9h3l-4 4-4-4h3zm7-4l1.013.007L11 9.351l3.225 2.106-.607.925L10 10V5z"/></svg> Member for <span title="2010-11-15 19:35:13Z">6 years, 6 months</span> </li> <li> <svg role="icon" class="svg-icon iconEye" width="18" height="18" viewBox="0 0 18 18"><path d="M8.999 3C14.279 3 18 8.5 18 8.5S14.28 14 8.999 14C3.719 14-.002 8.5-.002 8.5s3.72-5.5 9-5.5zM9 12.75a4.299 4.299 0 0 0 4.25-4.25A4.25 4.25 0 1 0 9 12.75zm0-2a2.25 2.25 0 1 1 0-4.5 2.25 2.25 0 0 1 0 4.5z"/></svg> 13,641 profile views </li> <li> <svg role="icon" class="svg-icon iconClock" width="18" height="18" viewBox="0 0 18 18"><path d="M9 17A8 8 0 1 1 9 1a8 8 0 0 1 0 16zm0-2A6 6 0 1 0 9 3a6 6 0 0 0 0 12zM8 5l1.013.007L9 9.351l3.225 2.106-.607.925L8 10V5z"/></svg> Last seen <span title="2017-06-05 01:30:57Z" class="relativetime">10 hours ago</span> </li> </ul> HTML; $doc = new DOMDocument; @$doc->loadHTML($html); $xpath = new DOMXpath($doc); $search = [ 'github' => 'iconGitHub', 'twitter' => 'iconTwitter', ]; $result = []; foreach ($search as $key => $className) { $nodeList = $xpath->query("//li[svg[contains(concat(' ', normalize-space(@class), ' '), ' {$className} ')]]/a"); if ($nodeList->length === 0) { continue; } $a = $nodeList->item(0); $result[$key] = [ 'username' => $a->textContent, 'url' => $a->getAttribute('href'), ]; } var_dump($result);
Output for 5.6.38, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
array(2) { ["github"]=> array(2) { ["username"]=> string(6) "PeeHaa" ["url"]=> string(25) "https://github.com/PeeHaa" } ["twitter"]=> array(2) { ["username"]=> string(8) "PHPeeHaa" ["url"]=> string(28) "https://twitter.com/PHPeeHaa" } }

preferences:
228.86 ms | 404 KiB | 247 Q