mb_convert_encoding
Description
The mb_convert_encoding of Multibyte String for PHP 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; ?>
🐘
Links
Multibyte String
- mb_check_encoding
- mb_chr
- mb_convert_case
- mb_convert_kana
- mb_convert_variables
- mb_decode_mimeheader
- mb_decode_numericentity
- mb_detect_encoding
- mb_detect_order
- mb_encode_mimeheader
- mb_encode_numericentity
- mb_encoding_aliases
- mb_ereg
- mb_ereg_match
- mb_ereg_replace
- mb_ereg_replace_callback
- mb_ereg_search
- mb_ereg_search_getpos
- mb_ereg_search_getregs
- mb_ereg_search_init
- mb_ereg_search_pos
- mb_ereg_search_regs
- mb_ereg_search_setpos
- mb_eregi
- mb_eregi_replace
- mb_get_info
- mb_http_input
- mb_http_output
- mb_internal_encoding
- mb_language
- mb_list_encodings
- mb_ord
- mb_output_handler
- mb_parse_str
- mb_preferred_mime_name
- mb_regex_encoding
- mb_regex_set_options
- mb_scrub
- mb_send_mail
- mb_split
- mb_str_pad
- mb_str_split
- mb_strcut
- mb_strimwidth
- mb_stripos
- mb_stristr
- mb_strlen
- mb_strpos
- mb_strrchr
- mb_strrichr
- mb_strripos
- mb_strrpos
- mb_strstr
- mb_strtolower
- mb_strtoupper
- mb_strwidth
- mb_substitute_character
- mb_substr
- mb_substr_count