must be a valid encoding, “%s” given

Description

The encoding arguments, in any mb_ function, must be a supported encoding. Otherwise, the mbstring extension doesn’t know how to handle it.

The current list of encodings is available with the function mb_list_encodings(). Encoding names are case insensitive.

The list of supported encoding depends on the PHP version. Some are added or removed, depending on the version.

Example

<?php

     print mb_chr(128024, 'UTF-8')); // emoji of an elephant

     //Argument #2 ($encoding) must be a valid encoding, "elephpant" given
     print mb_chr($value, 'elephpant'));
?>

Literal Examples

  • must be a valid encoding, “qprint” given

  • must be a valid encoding, “uuencode” given

Solutions

  • Check the encoding with mb_list_encodings() before using one.