3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function replace($row){ $replaced = preg_replace_callback("~(\<span class=\"itemopener\"\>)(\d{2})\s(top\</span\>.*\<span class=\"allopener\"\>).{3}(\</span\>)~iU", function($matches){ $str = $matches[1] . $matches[3] . $matches[2] . $matches[4]; return $str; }, $row); return $replaced; } $s = '<span class="itemopener">82 top</span>&nbsp;<span class="allopener">all</span>'; $replaced = replace($s); echo "<pre>" . print_r($replaced, 1) . "</pre>"; exit();
based on TqX7n
Output for 5.5.0 - 7.3.1
<pre><span class="itemopener">top</span>&nbsp;<span class="allopener">82</span></pre>