<?php
$htmlData = '<h1><span> test </span>
<span> test </span>
<span> test </span>
<span> test </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, "&nbsp;") == 5) && (str_word_count($htmlToMatch) == 5)) {
$outString = str_replace($match, '<b style="width:14px; display: inline-block;"> </b>', $matches[0]);
} else if (substr_count($htmlToMatch, "&nbsp;") == 20) {
$outString = str_replace($match, '<b style="width:35px; display: inline-block;"> </b>', $matches[0]);
}
}
return $outString == '' ? $matches[0] : $outString;
}
preferences:
34.3 ms | 402 KiB | 5 Q