mb_convert_variables()
(PHP 4 >= 4.0.6, PHP 5, PHP 7)
转换一个或多个变量的字符编码
说明
mb_convert_variables(string $to_encoding, mixed $from_encoding, mixed&$vars[,mixed&$...
]): string
将变量$vars的编码从$from_encoding转换成编码$to_encoding。
mb_convert_variables()会拼接变量数组或对象中的字符串来检测编码,因为短字符串的检测往往会失败。因此,不能在一个数组或对象中混合使用编码。
参数
- $to_encoding
将string转换成这个编码。
- $from_encoding
$from_encoding可以指定为一个array或者逗号分隔的string,它将尝试根据
from-coding
来检测编码。当省略了$from_encoding,将使用detect_order。- $vars
$vars是要转换的变量的引用。参数可以接受 String、Array 和 Object 的类型。mb_convert_variables()假设所有的参数都具有同样的编码。
- ...
额外的$vars。
返回值
成功时返回转换前的字符编码,失败时返回FALSE
。
范例
mb_convert_variables()例子
<?php /* 转换变量 $post1、$post2 编码为内部(internal)编码 */ $interenc = mb_internal_encoding(); $inputenc = mb_convert_variables($interenc, "ASCII,UTF-8,SJIS-win", $post1, $post2); ?>
Last version of this function (php 5.6.27 and php7.0.12) have a bug https://bugs.php.net/bug.php?id=73407
This function has a bug on recursion detection. https://bugs.php.net/bug.php?id=66964