mb_convert_variables()

mb_convert_variables() — Convert character code in variable(s).

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.

What it does

Converts character encoding of variables var and vars in encoding from_encoding to encoding to_encoding.

Signature

mb_convert_variables(string $to_encoding, array|string $from_encoding, mixed &$var, mixed &...$vars): string|false

Parameters

ParameterTypeWhat it takes
$to_encodingstringThe encoding that the string is being converted to.
$from_encodingarray|stringThe current encoding of the variables. Multiple encodings may be specified as an array or comma separated string, in which case the encoding is detected among the listed encodings. "auto" is expanded according to the mbstring.language INI setting.
&$varmixedvar is the reference to the variable being converted. String, Array and Object are accepted. mb_convert_variables() assumes all parameters have the same encoding.
&...$varsmixedAdditional vars.

Return value

The character encoding before conversion for success, or false for failure.

Example

A runnable snippet:

/* Convert variables $post1, $post2 to internal encoding */ $interenc = mb_internal_encoding(); $inputenc = mb_convert_variables($interenc, "ASCII,UTF-8,SJIS-win", $post1, $post2);

All PHP 8.5 built-in functions

Reference card built from the PHP manual page mb_convert_variables() (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.