mb_convert_variables

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

mb_convert_variables轉換一個或多個變量的字符編碼

說明

mb_convert_variables(
    string $to_encoding,
    mixed $from_encoding,
    mixed &$vars,
    mixed &$... = ?
): string

將變量 vars 的編碼從 from_encoding 轉換成編碼 to_encoding

mb_convert_variables() 會拼接變量數(shù)組或對象中的字符串來檢測編碼,因為短字符串的檢測往往會失敗。因此,不能在一個數(shù)組或對象中混合使用編碼。

參數(shù)

to_encoding

string 轉換成這個編碼。

from_encoding

from_encoding 可以指定為一個 array 或者逗號分隔的 string,它將嘗試根據(jù) from-coding 來檢測編碼。 當省略了 from_encoding,將使用 detect_order

vars

vars 是要轉換的變量的引用。 參數(shù)可以接受 String、Array 和 Object 的類型。 mb_convert_variables() 假設所有的參數(shù)都具有同樣的編碼。

...

額外的 vars。

返回值

成功時返回轉換前的字符編碼,失敗時返回 false。

范例

示例 #1 mb_convert_variables() 例子

<?php
/* 轉換變量 $post1、$post2 編碼為內(nèi)部(internal)編碼 */
$interenc mb_internal_encoding();
$inputenc mb_convert_variables($interenc"ASCII,UTF-8,SJIS-win"$post1$post2);
?>