php encoding_error ai_generated true

Warning: mb_convert_encoding(): Illegal character encoding specified in /var/www/app/src/Utils/TextCleaner.php on line 18

ID: php/mb-convert-encoding-illegal-character

Also available as: JSON · Markdown · 中文
90%Fix Rate
86%Confidence
1Evidence
2024-07-05First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
PHP 8.1 active
PHP 8.2 active
PHP 8.3 active

Root Cause

The encoding name passed to mb_convert_encoding is not recognized by the mbstring extension, often due to a typo or unsupported encoding.

generic

中文

传递给 mb_convert_encoding 的编码名称未被 mbstring 扩展识别,通常是由于拼写错误或不支持的编码。

Official Documentation

https://www.php.net/manual/en/function.mb-convert-encoding.php

Workarounds

  1. 95% success Verify the encoding name against the list of supported encodings using mb_list_encodings() and correct any typos.
    Verify the encoding name against the list of supported encodings using mb_list_encodings() and correct any typos.
  2. 90% success Use mb_detect_encoding() to auto-detect the encoding before conversion, with a fallback to a safe encoding like UTF-8.
    Use mb_detect_encoding() to auto-detect the encoding before conversion, with a fallback to a safe encoding like UTF-8.

中文步骤

  1. Verify the encoding name against the list of supported encodings using mb_list_encodings() and correct any typos.
  2. Use mb_detect_encoding() to auto-detect the encoding before conversion, with a fallback to a safe encoding like UTF-8.

Dead Ends

Common approaches that don't work:

  1. 95% fail

    Setting default_charset in php.ini to a different value does not affect mb_convert_encoding's encoding parameter validation.

  2. 70% fail

    Using iconv() instead of mb_convert_encoding may work for some encodings but introduces a new dependency and may not support all encodings.

  3. 85% fail

    Passing an empty string as encoding will still trigger this warning because empty is not a valid encoding name.