...
-> wrap simulation
* - newlines are stripped, whitespace collapses -> \s+ collapse
* - whitespace BETWEEN tags is dropped
* (" " becomes "") -> >\s+< join
* - entities may be re-encoded ("×" vs "×") -> entity decode
*
* Anything beyond that (real markup changes) still counts as different.
* The Phase-2 change watch compares workbook against imported_values instead
* of the database precisely because storage transforms exist - this class
* only keeps the LIVE comparison honest.
*/
final class RteCompare
{
public static function equal(string $stored, string $incoming): bool
{
$storedNorm = self::normalize($stored);
if ($storedNorm === self::normalize($incoming)) {
return true;
}
return $storedNorm === self::normalize('' . $incoming . '
');
}
private static function normalize(string $html): string
{
$s = html_entity_decode($html, ENT_QUOTES | ENT_HTML5, 'UTF-8');
$s = (string)preg_replace('/\s+/u', ' ', $s);
$s = (string)preg_replace('/>\s+', '><', $s);
return trim($s);
}
}