mb_internal_encoding()
mb_internal_encoding() — Set/Get internal character encoding.
Built-in function of PHP 8.5. The manual lists it as available in PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
Signature
mb_internal_encoding(?string $encoding = null): string|bool
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $encoding | ?string | encoding is the character encoding name used for the HTTP input character encoding conversion, HTTP output character encoding conversion, and the default character encoding for string functions defined by the mbstring module. You should notice that the internal encoding is totally different from the one for multibyte regex. |
Return value
If encoding is set, then Returns true on success or false on failure. In this case, the character encoding for multibyte regex is NOT changed. If encoding is omitted, then the current character encoding name is returned.
Example
A runnable snippet:
/* Set internal character encoding to UTF-8 */ mb_internal_encoding("UTF-8"); /* Display current internal character encoding */ echo mb_internal_encoding();
Changelog
| Version | Change |
|---|---|
| 8.0.0 | encoding is nullable now. |
| 8.0.0 | Now throws a ValueError if encoding is an invalid encoding. Previously, an E_WARNING was emitted and false was returned. |
See also
mb_http_input(), mb_http_output(), mb_detect_order(), mb_regex_encoding()
All PHP 8.5 built-in functions
Reference card built from the PHP manual page mb_internal_encoding() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.