<?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);
You have javascript disabled. You will not be able to edit any code.