“mb_convert_encoding(): Handling HTML entities via mbstring is deprecated”: the fix
Short answer
It’s a deprecation notice from PHP 8.2 and later: a plugin or theme converts text to or from HTML entities (like é for é) with mb_convert_encoding() and the pseudo-encoding 'HTML-ENTITIES'. The conversion still works; PHP adds the notice because HTML-ENTITIES isn’t a real text encoding. PHP’s own message names the replacements: htmlspecialchars(), htmlentities(), or mb_encode_numericentity() and mb_decode_numericentity(). Update the plugin, or send the message to its developer.
The message, exactly
An importer turns accented text into HTML entities before processing it. PHP 8.1 converts silently; PHP 8.2 converts the same way and adds the notice:
wp-content/plugins/old-importer/import.php
<?php
echo mb_convert_encoding('Café', 'HTML-ENTITIES', 'UTF-8'), "\n";
CaféDeprecated: mb_convert_encoding(): Handling HTML entities via mbstring is deprecated; use htmlspecialchars, htmlentities, or mb_encode_numericentity/mb_decode_numericentity instead in /var/www/html/wp-content/plugins/old-importer/import.php on line 2
Caféphp.net, in the PHP 8.2 deprecations: “Usage of the QPrint, Base64, Uuencode, and HTML-ENTITIES ’text encodings’ is deprecated for all MBString functions.” (php.net)
What it means
mb_convert_encoding() converts text between real encodings, such as UTF-8 and ISO-8859-1. HTML-ENTITIES was a shortcut that let the same function write é instead of é. It isn’t an encoding of characters, and PHP has dedicated functions for HTML entities, so PHP 8.2 marked the shortcut as deprecated.
Who fixes it
- Find the plugin or theme: the folder after
wp-content/plugins/orwp-content/themes/in the message. - Update it (Dashboard → Updates).
- Already on the latest version? Send one full line of the message to its developer.
- Meanwhile, keep notices off your pages: the WordPress debug log.
Found before you switch
The call is in the code, so a check that reads code finds it while your site still runs PHP 8.1:
The other PHP 8.2 changes, and utf8_encode() from the same kind of importers: WordPress and PHP 8.2 and “utf8_encode() is deprecated”.
Key takeaways
- A deprecation notice from PHP 8.2 and later; the text is still converted.
- It comes from
mb_convert_encoding( $text, 'HTML-ENTITIES', … ), for example in importers and HTML parsers. - PHP 8.2 deprecated the same use of
'BASE64','UUENCODE'and'QPrint'in mbstring. - Replacements:
htmlentities()/html_entity_decode(), ormb_encode_numericentity()/mb_decode_numericentity(). - A check that reads code finds it before you upgrade.
Frequently asked questions
Where does this usually come from?
A common source is code that loads HTML into PHP’s DOM parser (DOMDocument::loadHTML()): converting the text to HTML entities first was a widespread way to keep accented characters intact.
Will accented characters break?
Not on PHP 8.2 to 8.5: the conversion still works and only adds a notice. The plugin should switch to one of the replacements before a future PHP version removes this use.
Is the replacement output identical?
For text with accents, htmlentities() gives the same entities, as in our test. It also converts <, >, & and quotes, which the old call left alone, so the developer chooses the replacement that fits.
Check your own site before you upgrade
CompatNav is a free WordPress plugin. It reads the code of your plugins and themes on your own server and tells you, in plain words, what will break and what will only show notices on the PHP version you choose. It never changes your code. It can’t see problems that only appear while code runs with real data, so a quick check of your site after the upgrade still matters.
Sources
About the code examples: each output is the real output of the code shown, run with the official PHP builds, without a php.ini, with all errors reported and displayed. Only the file path was replaced by a neutral server path.