{
  "id": "php/mbstring-illegal-character",
  "signature": "Warning: mb_convert_encoding(): Illegal character encoding specified in /var/www/app/src/Utils/TextCleaner.php on line 15",
  "signature_zh": "警告：mb_convert_encoding()：指定了非法字符编码，位于 /var/www/app/src/Utils/TextCleaner.php 第 15 行",
  "regex": "/mb_convert_encoding\\(\\): Illegal character encoding specified/",
  "domain": "php",
  "category": "encoding_error",
  "subcategory": null,
  "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.",
  "root_cause_type": "generic",
  "root_cause_zh": "传递给 mb_convert_encoding() 的编码名称无效或不支持，通常由编码字符串拼写错误或使用了 mbstring 扩展无法识别的别名引起。",
  "versions": [
    {
      "version": "7.4",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "8.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "8.1",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "8.2",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "8.3",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "default_charset affects PHP's output encoding, not the input encoding parameter for mb_convert_encoding.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Suppressing warnings hides the problem but does not fix the encoding issue, potentially leading to corrupted data.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "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'); }",
      "success_rate": 0.95,
      "how": "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'); }",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use iconv() as a fallback for unsupported encodings: $result = @iconv($fromEncoding, 'UTF-8//IGNORE', $string);",
      "success_rate": 0.85,
      "how": "Use iconv() as a fallback for unsupported encodings: $result = @iconv($fromEncoding, 'UTF-8//IGNORE', $string);",
      "condition": "",
      "sources": []
    },
    {
      "action": "Correct the encoding name to a standard one recognized by mbstring, e.g., change 'utf8' to 'UTF-8', 'latin1' to 'ISO-8859-1'.",
      "success_rate": 0.9,
      "how": "Correct the encoding name to a standard one recognized by mbstring, e.g., change 'utf8' to 'UTF-8', 'latin1' to 'ISO-8859-1'.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "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'."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://www.php.net/manual/en/function.mb-convert-encoding.php",
  "official_doc_section": null,
  "error_code": "E_WARNING",
  "verification_tier": "ai_generated",
  "confidence": 0.83,
  "fix_success_rate": 0.9,
  "resolvable": "true",
  "first_seen": "2024-09-22",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}