# Warning: mb_convert_encoding(): Illegal character encoding specified in /var/www/app/src/Utils/TextCleaner.php on line 15

- **ID:** `php/mbstring-illegal-character`
- **Domain:** php
- **Category:** encoding_error
- **Error Code:** `E_WARNING`
- **Verification:** ai_generated
- **Fix Rate:** 90%

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

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 7.4 | active | — | — |
| 8.0 | active | — | — |
| 8.1 | active | — | — |
| 8.2 | active | — | — |
| 8.3 | active | — | — |

## Workarounds

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'); }** (95% success)
   ```
   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);** (85% success)
   ```
   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'.** (90% success)
   ```
   Correct the encoding name to a standard one recognized by mbstring, e.g., change 'utf8' to 'UTF-8', 'latin1' to 'ISO-8859-1'.
   ```

## Dead Ends

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