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

- **ID:** `php/mbstring-illegal-character`
- **领域:** php
- **类别:** encoding_error
- **错误码:** `E_WARNING`
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

传递给 mb_convert_encoding() 的编码名称无效或不支持，通常由编码字符串拼写错误或使用了 mbstring 扩展无法识别的别名引起。

## 版本兼容性

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

## 解决方案

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'); }
   ```
2. ```
   Use iconv() as a fallback for unsupported encodings: $result = @iconv($fromEncoding, 'UTF-8//IGNORE', $string);
   ```
3. ```
   Correct the encoding name to a standard one recognized by mbstring, e.g., change 'utf8' to 'UTF-8', 'latin1' to 'ISO-8859-1'.
   ```

## 无效尝试

- **** — default_charset affects PHP's output encoding, not the input encoding parameter for mb_convert_encoding. (95% 失败率)
- **** — Suppressing warnings hides the problem but does not fix the encoding issue, potentially leading to corrupted data. (90% 失败率)
