# 警告：mb_convert_encoding()：指定了非法字符编码，位于 /var/www/app/src/Utils/TextCleaner.php 第 18 行

- **ID:** `php/mb-convert-encoding-illegal-character`
- **领域:** php
- **类别:** encoding_error
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

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

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| PHP 8.1 | active | — | — |
| PHP 8.2 | active | — | — |
| PHP 8.3 | active | — | — |

## 解决方案

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.
   ```

## 无效尝试

- **** — Setting default_charset in php.ini to a different value does not affect mb_convert_encoding's encoding parameter validation. (95% 失败率)
- **** — Using iconv() instead of mb_convert_encoding may work for some encodings but introduces a new dependency and may not support all encodings. (70% 失败率)
- **** — Passing an empty string as encoding will still trigger this warning because empty is not a valid encoding name. (85% 失败率)
