3v4l.org

run code in 300+ PHP versions simultaneously
<?php $htmlData = '<h1><span> test&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span> <span> test&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span> <span> test&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span> <span> test&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span> </h1> '; echo $htmlData = preg_replace_callback('/<li(.*?)>(.*?)<\/li>(.*?)/s', 'self::replaceRule19Matches', $htmlData); function replaceRule19Matches($matches) { $outString = ''; $matchList = []; preg_match_all('/<span[^>]*>(.*?)<\/span>/s', $matches[0], $matchList); foreach ($matchList[0] as $match) { $htmlToMatch = htmlentities($match); if ((substr_count($htmlToMatch, "&amp;nbsp;") == 5) && (str_word_count($htmlToMatch) == 5)) { $outString = str_replace($match, '<b style="width:14px; display: inline-block;">&nbsp;</b>', $matches[0]); } else if (substr_count($htmlToMatch, "&amp;nbsp;") == 20) { $outString = str_replace($match, '<b style="width:35px; display: inline-block;">&nbsp;</b>', $matches[0]); } } return $outString == '' ? $matches[0] : $outString; }

preferences:
34.3 ms | 402 KiB | 5 Q