Open In App

PHP mb_convert_variables() Function

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:

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
$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
$array = array(
  "name" => "GeeksforGeeks",
  "email" => "geeks@example.com"
 );
mb_convert_variables('UTF-8', 'ISO-8859-1', $array);
print_r($array);   
?>

Output:

Array
(
    [name] => GeeksforGeeks
    [email] => geeks@example.com
)

Reference: https://www.php.net/manual/en/function.mb-convert-variables.php

Article Tags :