PHP 8.3.4 Released!

mb_convert_variables

(PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8)

mb_convert_variables转换一个或多个变量的字符编码

说明

mb_convert_variables(
    string $to_encoding,
    array|string $from_encoding,
    mixed &$var,
    mixed &...$vars
): string|false

将变量 varvars 的编码从 from_encoding 转换成编码 to_encoding

mb_convert_variables() 会拼接变量数组或对象中的字符串来检测编码,因为短字符串的检测往往会失败。因此,不能在一个数组或对象中混合使用编码。

参数

to_encoding

string 转换成这个编码。

from_encoding

from_encoding 可以指定为一个 array 或者逗号分隔的 string,它将尝试根据 from-coding 来检测编码。 当省略了 from_encoding,将使用 detect_order

var

var 是要转换的变量的引用。 参数可以接受 String、Array 和 Object 的类型。 mb_convert_variables() 假设所有的参数都具有同样的编码。

vars

额外的 var

返回值

成功时返回转换前的字符编码,失败时返回 false

示例

示例 #1 mb_convert_variables() 示例

<?php
/* 转换变量 $post1、$post2 编码为内部(internal)编码 */
$interenc = mb_internal_encoding();
$inputenc = mb_convert_variables($interenc, "ASCII,UTF-8,SJIS-win", $post1, $post2);
?>

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top