E_WARNING
php
encoding_error
ai_generated
true
Warning: mb_convert_encoding(): Illegal character encoding specified in /var/www/app/src/Utils/TextCleaner.php on line 15
ID: php/mbstring-illegal-character
90%Fix Rate
83%Confidence
1Evidence
2024-09-22First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 7.4 | active | — | — | — |
| 8.0 | active | — | — | — |
| 8.1 | active | — | — | — |
| 8.2 | active | — | — | — |
| 8.3 | active | — | — | — |
Root Cause
An invalid or unsupported encoding name is passed to mb_convert_encoding(), often due to a typo in the encoding string or using an alias not recognized by the mbstring extension.
generic中文
传递给 mb_convert_encoding() 的编码名称无效或不支持,通常由编码字符串拼写错误或使用了 mbstring 扩展无法识别的别名引起。
Official Documentation
https://www.php.net/manual/en/function.mb-convert-encoding.phpWorkarounds
-
95% success Validate the encoding name before conversion using mb_list_encodings(): $enc = 'utf-8'; if (in_array(strtolower($enc), array_map('strtolower', mb_list_encodings()))) { $result = mb_convert_encoding($string, 'UTF-8', $enc); } else { throw new InvalidArgumentException('Unsupported encoding'); }
Validate the encoding name before conversion using mb_list_encodings(): $enc = 'utf-8'; if (in_array(strtolower($enc), array_map('strtolower', mb_list_encodings()))) { $result = mb_convert_encoding($string, 'UTF-8', $enc); } else { throw new InvalidArgumentException('Unsupported encoding'); } -
85% success Use iconv() as a fallback for unsupported encodings: $result = @iconv($fromEncoding, 'UTF-8//IGNORE', $string);
Use iconv() as a fallback for unsupported encodings: $result = @iconv($fromEncoding, 'UTF-8//IGNORE', $string);
-
90% success Correct the encoding name to a standard one recognized by mbstring, e.g., change 'utf8' to 'UTF-8', 'latin1' to 'ISO-8859-1'.
Correct the encoding name to a standard one recognized by mbstring, e.g., change 'utf8' to 'UTF-8', 'latin1' to 'ISO-8859-1'.
中文步骤
Validate the encoding name before conversion using mb_list_encodings(): $enc = 'utf-8'; if (in_array(strtolower($enc), array_map('strtolower', mb_list_encodings()))) { $result = mb_convert_encoding($string, 'UTF-8', $enc); } else { throw new InvalidArgumentException('Unsupported encoding'); }Use iconv() as a fallback for unsupported encodings: $result = @iconv($fromEncoding, 'UTF-8//IGNORE', $string);
Correct the encoding name to a standard one recognized by mbstring, e.g., change 'utf8' to 'UTF-8', 'latin1' to 'ISO-8859-1'.
Dead Ends
Common approaches that don't work:
-
95% fail
default_charset affects PHP's output encoding, not the input encoding parameter for mb_convert_encoding.
-
90% fail
Suppressing warnings hides the problem but does not fix the encoding issue, potentially leading to corrupted data.