Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

mb_convert_encoding

Description

Convert a string from one character encoding to another

Syntax

mb_convert_encoding(
    array|string $string,
    string $to_encoding,
    array|string|null $from_encoding = null
): array|string|false

Parameters

string

The string or array to be converted.

to_encoding

The desired encoding of the result.

from_encoding

The current encoding used to interpret string. Multiple encodings may be specified as an array or comma separated list, in which case the correct encoding will be guessed using the same algorithm as mb_detect_encoding().

If from_encoding is omitted or null, the mbstring.internal_encoding setting will be used if set, otherwise the default_charset setting.

Return

The encoded string or array on success, or false on failure.

Examples

1 · string · array to_encoding

<?

$string = ["🐘", "🐘"];
$to_encoding = 'UTF-8';

$return = mb_convert_encoding($string, $to_encoding);

print_r($return);

?>
Array
(
    [0] => 🐘
    [1] => 🐘
)

2 · string · string to_encoding

<?

$string = "🐘";
$to_encoding = 'UTF-8';

$return = mb_convert_encoding($string, $to_encoding);

echo $return;

?>
🐘

3 · from_encoding · array

<?

$string = "🐘";
$to_encoding = 'UTF-8';
$from_encoding = ['auto', 'ASCII', 'ISO-8859-1'];

$return = mb_convert_encoding($string, $to_encoding, $from_encoding);

echo $return;

?>
🐘

4 · from_encoding · string

<?

$string = "🐘";
$to_encoding = 'UTF-8';
$from_encoding = 'auto, ASCII, ISO-8859-1';

$return = mb_convert_encoding($string, $to_encoding, $from_encoding);

echo $return;

?>
🐘

5 · from_encoding · null

<?

$string = "🐘";
$to_encoding = 'UTF-8';
$from_encoding = null;

$return = mb_convert_encoding($string, $to_encoding, $from_encoding);

echo $return;

?>
🐘
HomeMenu