1.php加载mbstring
extension=php_mbstring.dll
2.配置mbstring
[mbstring]
; language for internal character representation.
; http://php.net/mbstring.language
mbstring.language = Chinese
; internal/script encoding.
; Some encoding cannot work as internal encoding.
; (e.g. SJIS, BIG5, ISO-2022-*)
; http://php.net/mbstring.internal-encoding
mbstring.internal_encoding =UTF-8
; http input encoding.
; http://php.net/mbstring.http-input
mbstring.http_input = auto
; http output encoding. mb_output_handler must be
; registered as output buffer to function
; http://php.net/mbstring.http-output
mbstring.http_output = UTF-8
; enable automatic encoding translation according to
; mbstring.internal_encoding setting. Input chars are
; converted to internal encoding by setting this to On.
; Note: Do _not_ use automatic encoding translation for
; portable libs/applications.
; http://php.net/mbstring.encoding-translation
mbstring.encoding_translation = On
3.我的代码:
function fantigetjianti($str) {
$fantis = "";
include "fanti2jiantiData.php"; //加载繁体字数组
for ($i = 0; $i <= mb_strlen($str); $i++) {
$fanti = mb_substr($str, $i, 1);
$jianti = $fantiData[$fanti];
if (empty($jianti)) {
$jianti = $fanti;
}
$fantis .=$jianti;
}
return $fantis;
}