3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<HTML <div> <h1>title</h1> and <h2>title 2</h2> <h2 data-formula="a > b" class="regex_is_DOM_unaware">Monkeywrench</h2> <h1 class="classname">test <span>This isn't even a </h tag</span></h1> </div> HTML; var_export( preg_match_all( '|<\s*h[1-2](?:.*)>(.*)</\s*h|Ui', $html, $matches ) ? $matches[1] // capture group 1 : [] ); /* Desired result but not what is provided: array ( 0 => 'title', 1 => 'title 2', 2 => 'Monkeywrench', 3 => 'test <span>This isn't even a </h tag</span>' ) */

preferences:
29.76 ms | 405 KiB | 5 Q