php[world] 2018 - Call for Speakers


(PHP 4 >= 4.0.6, PHP 5, PHP 7)

mb_convert_variablesConvert character code in variable(s)


string mb_convert_variables ( string $to_encoding , mixed $from_encoding , mixed &$vars [, mixed &$... ] )

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

mb_convert_variables() join strings in Array or Object to detect encoding, since encoding detection tends to fail for short strings. Therefore, it is impossible to mix encoding in single array or object.

Elenco dei parametri


The encoding that the string is being converted to.


from_encoding is specified as an array or comma separated string, it tries to detect encoding from from-coding. When from_encoding is omitted, detect_order is used.


vars is the reference to the variable being converted. String, Array and Object are accepted. mb_convert_variables() assumes all parameters have the same encoding.


Additional vars.

Valori restituiti

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


Example #1 mb_convert_variables() example

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

add a note add a note

User Contributed Notes 2 notes

ryosuke_i_628 at yahoo dot co dot jp
4 years ago
This function has a bug on recursion detection.
ivan dot plotnikov at corp dot oft-e dot com
1 year ago
Last version of this function (php 5.6.27 and php7.0.12) have a bug
To Top