php encoding_error ai_generated true

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

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

其他格式: JSON · Markdown 中文 · English
90%修复率
86%置信度
1证据数
2024-07-05首次发现

版本兼容性

版本状态引入弃用备注
PHP 8.1 active
PHP 8.2 active
PHP 8.3 active

根因分析

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

English

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

generic

官方文档

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

解决方案

  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.

无效尝试

常见但无效的做法:

  1. 95% 失败

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

  2. 70% 失败

    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% 失败

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