mb_convert_encoding() 函數是 PHP 中的內置函數,可將字符串轉換為另一種字符編碼。
用法:
mb_convert_encoding( array|string $string, string $to_encoding, array|string|null $from_encoding = null ): array|string|false
Parameters: 該函數有3個參數:
- string: 參數指定要轉換的字符串或數組。
- to_encoding: 該參數指定結果所需的編碼。
- from_encoding: 如果mbstring.internal_encoding將使用設置,如果from_encoding為空或未指定,否則default_charset將使用設置。
返回值:如果函數執行成功,該函數將返回一個編碼字符串,否則將返回 false。
示例 1:下麵的代碼演示了mb_convert_encoding()函數。
PHP
<?php
// UTF-8 string to be converted to ASCII
$string = "Café au lait";
// Convert UTF-8 string to ASCII
$ascii_string = mb_convert_encoding($string, "ASCII");
// Output the converted string
echo $ascii_string;
?>
輸出:
Caf? au lait
示例 2:下麵的代碼演示了mb_convert_encoding()函數。
PHP
<?php
// ISO-8859-1 string to be converted to UTF-8
$string = "Björk";
// Convert ISO-8859-1 string to UTF-8
$utf8_string = mb_convert_encoding(
$string, "UTF-8", "ISO-8859-1");
// Output the converted string
echo $utf8_string;
?>
輸出:
Björk
參考: https://www.php.net/manual/en/function.mb-convert-encoding.php
相關用法
- PHP mb_convert_case()用法及代碼示例
- PHP mb_convert_variables()用法及代碼示例
- PHP mb_convert_kana()用法及代碼示例
- PHP mb_check_encoding()用法及代碼示例
- PHP mb_chr()用法及代碼示例
- PHP mb_strlen()用法及代碼示例
- PHP mb_substr_count()用法及代碼示例
- PHP mb_substr()用法及代碼示例
- PHP mb_substitute_character()用法及代碼示例
- PHP mb_detect_order()用法及代碼示例
- PHP mb_strtolower()用法及代碼示例
- PHP mb_strtoupper()用法及代碼示例
- PHP mb_str_split()用法及代碼示例
- PHP mb_ereg()用法及代碼示例
- PHP mb_http_input()用法及代碼示例
- PHP mb_parse_str()用法及代碼示例
- PHP mb_encode_numericentity()用法及代碼示例
- PHP mb_encoding_aliases()用法及代碼示例
- PHP mb_strrchr()用法及代碼示例
- PHP mb_strimwidth()用法及代碼示例
- PHP mb_ereg_search_regs()用法及代碼示例
- PHP mb_ereg_search_init()用法及代碼示例
- PHP mb_stristr()用法及代碼示例
- PHP mb_ereg_search_pos()用法及代碼示例
- PHP mb_split()用法及代碼示例
注:本文由純淨天空篩選整理自neeraj3304大神的英文原創作品 PHP mb_convert_encoding() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。