3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<HTML <a href="#">hello</a> <abbr href="#">FYI</abbr> <a title="goodbye">later</a> <a href=https://example.com>no quoted attributes</a> <A href="https://example.com" title="some title" data-key="{\'key\':\'adf0a8dfq<>*1$4%\'">a link with data attribute</A> and this is <a title="hello">not a hyperlink</a> but simply an anchor tag HTML; $dom = new DOMDocument; $dom->loadHTML($html); $xpath = new DOMXPath($dom); $linkText = []; foreach ($xpath->evaluate("//a[@href]") as $node) { $linkText[] = $node->nodeValue; } var_export($linkText); echo "\n --- if you don't care about the href attribute existing --- \n"; $doc = new DOMDocument(); $doc->loadHTML($html); $aTags = []; foreach ($doc->getElementsByTagName('a') as $a) { $aTags[] = $a->nodeValue; } var_export($aTags);

preferences:
41.79 ms | 404 KiB | 5 Q