3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = '<div class="something">What </div> if it it is is same <div style="color:red;">same </div>'; echo preg_replace_callback('~</?\b[^<>]+>(*SKIP)(*F)|\w+~', function($matches) { static $counter = 0; return "<span class=\"splits split".(++$counter)."\">{$matches[0]}</span>"; }, $string);

preferences:
176.79 ms | 404 KiB | 5 Q