cabrerahector/wordpress-popular-posts

mb_convert_encoding() deprecation notice under PHP 8.2

cabrerahector opened this issue · 0 comments

Plugin is using mb_convert_encoding() in Output to fix some character encoding issues some users experience when using accented characters for example.

Under PHP 8.2, sites will start registering notices informing that "Handling HTML entities via mbstring is deprecated" (see PHP 8.2 Deprecation Warning in 6.2.1).

Potential solutions to test:

htmlspecialchars_decode(utf8_decode(htmlentities($html, ENT_COMPAT, 'utf-8', false)));
htmlspecialchars_decode(iconv('UTF-8', 'ISO-8859-1', htmlentities($html, ENT_COMPAT, 'UTF-8')), ENT_QUOTES);

or

$html = iconv($charset, 'UTF-8', $html);
$html = mb_encode_numericentity($html, [0x80, 0x10FFFF, 0, 0x1FFFFF], 'UTF-8');

(link, which is somewhat similar to php.net's solution below)

mb_encode_numericentity(htmlentities($html, ENT_QUOTES, 'UTF-8'), [0x80, 0x10FFFF, 0, ~0], 'UTF-8');

(although this last one seems a little bit hard to read which might not be great for future code maintenance.)