CssToInlineStyles icon indicating copy to clipboard operation
CssToInlineStyles copied to clipboard

`mb_encode_numericentity` vs `htmlspecialchars_decode(htmlentities($html))`

Open hirasso opened this issue 1 year ago • 0 comments

Hi there! This is actually not an issue with your library (which is amazing!), rather a question. Feel free to close this if you don't have the time right now :)

I'm in the process of migrating a few projects to PHP 8.2 and trying to find the correct replacement for this:

$document->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'))

While searching my code base, I found an old version of CssToInlineStyles that was also using this function. And I see that you have replaced it with this since then:

$document->loadHTML(mb_encode_numericentity($html, [0x80, 0x10FFFF, 0, 0x1FFFFF], 'UTF-8'));

https://github.com/tijsverkoyen/CssToInlineStyles/blob/83ee6f38df0a63106a9e4536e3060458b74ccedb/src/CssToInlineStyles.php#L116C29-L116C52

This looks very cryptic to me and I'd like to understand better what's going on here. In my (manual) tests, the following worked with all strings that I tested it with:

htmlspecialchars_decode(htmlentities($html));

But I'm a bit afraid that I'm missing something...

I'd be grateful for any insight you might have on the matter 🙂

hirasso avatar Jan 11 '24 07:01 hirasso