# 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`
- **Domain:** php
- **Category:** encoding_error
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

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

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| PHP 8.1 | active | — | — |
| PHP 8.2 | active | — | — |
| PHP 8.3 | active | — | — |

## Workarounds

1. **Verify the encoding name against the list of supported encodings using mb_list_encodings() and correct any typos.** (95% success)
   ```
   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.** (90% success)
   ```
   Use mb_detect_encoding() to auto-detect the encoding before conversion, with a fallback to a safe encoding like UTF-8.
   ```

## Dead Ends

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