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);
Output for git.master, git.master_jit, rfc.property-hooks
array ( 0 => 'hello', 1 => 'no quoted attributes', 2 => 'a link with data attribute', ) --- if you don't care about the href attribute existing --- array ( 0 => 'hello', 1 => 'later', 2 => 'no quoted attributes', 3 => 'a link with data attribute', 4 => 'not a hyperlink', )

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
190.79 ms | 406 KiB | 5 Q