<?php
$htmlData = '<h1><span> test </span>
<span> test </span>
<span> test </span>
<span> test </span>
</h1>
';
echo $htmlData = preg_replace_callback('/<li(.*?)>(.*?)<\/li>(.*?)/s', '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;
}
- Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
- <h1><span> test </span>
<span> test </span>
<span> test </span>
<span> test </span>
</h1>
preferences:
169.46 ms | 404 KiB | 193 Q