Thursday, September 4, 2025
HomeLanguagesPHP mb_convert_variables() Function

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:

  • $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

RELATED ARTICLES

Most Popular

Dominic
32263 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6626 POSTS0 COMMENTS
Nicole Veronica
11799 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11857 POSTS0 COMMENTS
Shaida Kate Naidoo
6749 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6696 POSTS0 COMMENTS
Umr Jansen
6716 POSTS0 COMMENTS