3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<HTML <h2>Title of post</h2> 1 category <strong>task 1</strong> 1 category <strong>task 2</strong> 1 category <strong>task 3</strong>&nbsp; HTML; $dom=new DOMDocument; $dom->loadHTML($html); $xpath = new DOMXPath($dom); foreach ($xpath->query('//h2/following-sibling::text()') as $node) { var_export(trim($node->textContent)); echo "\n"; }
Output for 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
'1 category' '1 category' '1 category' ' '

preferences:
103.5 ms | 1426 KiB | 4 Q