The mb_convert_variables() is an inbuilt function in PHP that transforms the character code into variables.
Syntax:
mb_convert_variables( $to_encoding, $from_encoding, $var, ...$vars ): string|false
Parameters: This function accepts four parameters that are described below:
- $to_encoding: The characters encoding converted into the variable.
- $from_encoding: This parameter is specified with the string separated with a comma or as an array. The detect_order will be used if omitted.
- $vars: The variable or array of variables to be converted. This parameter is passed by reference. The String, Array, and Object are taken by this variable.
- …$vars: This is an optional parameter. Additional variables are to be converted, and separated by commas.
Return values: If the conversion is successful, it will return “true” otherwise it will return “false”. If $vars is an array, the function returns an array of the converted variables.
Example 1: The following code demonstrates the mb_convert_variables() function.
PHP
<?php $string = "Hello, world!"; mb_convert_variables('UTF-8', 'ASCII', $string); echo $string; ?> |
Output:
Hello, world!
Example 2: The following code demonstrates the mb_convert_variables() function.
PHP
<?php $array = array( "name" => "neveropen", "email" => "neveropen@example.com" ); mb_convert_variables('UTF-8', 'ISO-8859-1', $array); print_r($array); ?> |
Output:
Array
(
[name] => neveropen
[email] => neveropen@example.com
)
Reference: https://www.php.net/manual/en/function.mb-convert-variables.php
