Thursday, January 29, 2026
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

1 COMMENT

Most Popular

Dominic
32477 POSTS0 COMMENTS
Milvus
122 POSTS0 COMMENTS
Nango Kala
6849 POSTS0 COMMENTS
Nicole Veronica
11978 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12065 POSTS0 COMMENTS
Shaida Kate Naidoo
6986 POSTS0 COMMENTS
Ted Musemwa
7222 POSTS0 COMMENTS
Thapelo Manthata
6934 POSTS0 COMMENTS
Umr Jansen
6916 POSTS0 COMMENTS