>php教程 >php手册 >php编码转换函数

php编码转换函数

WBOY
WBOY원래의
2016-06-13 10:38:42865검색

        一般情况下用 iconv,只有当遇到无法确定原编码是何种编码,或者iconv转化后无法正常显示时才用mb_convert_encoding 函数。

iconv函数语法 :
<font color="#000000"><font color="#0000bb"><?php <br></font><font color="#007700">echo </font><font color="#0000bb">iconv</font><font color="#007700">(</font><font color="#dd0000">"ISO-8859-1"</font><font color="#007700">, </font><font color="#dd0000">"UTF-8"</font><font color="#007700">, </font><font color="#dd0000">"This is a test."</font><font color="#007700">);<br></font><font color="#0000bb">?></font> </font>

mb_convert_encoding函数语法 :
<font color="#000000"><font color="#0000bb"><?php <br></font><font color="#ff8000">/* Convert internal character encoding to SJIS */<br></font><font color="#0000bb">$str </font><font color="#007700">= </font><font color="#0000bb">mb_convert_encoding</font><font color="#007700">(</font><font color="#0000bb">$str</font><font color="#007700">, </font><font color="#dd0000">"SJIS"</font><font color="#007700">);<br><br></font><font color="#ff8000">/* Convert EUC-JP to UTF-7 */<br></font><font color="#0000bb">$str </font><font color="#007700">= </font><font color="#0000bb">mb_convert_encoding</font><font color="#007700">(</font><font color="#0000bb">$str</font><font color="#007700">, </font><font color="#dd0000">"UTF-7"</font><font color="#007700">, </font><font color="#dd0000">"EUC-JP"</font><font color="#007700">);<br><br></font><font color="#ff8000">/* Auto detect encoding from JIS, eucjp-win, sjis-win, then convert str to UCS-2LE */<br></font><font color="#0000bb">$str </font><font color="#007700">= </font><font color="#0000bb">mb_convert_encoding</font><font color="#007700">(</font><font color="#0000bb">$str</font><font color="#007700">, </font><font color="#dd0000">"UCS-2LE"</font><font color="#007700">, </font><font color="#dd0000">"JIS, eucjp-win, sjis-win"</font><font color="#007700">);<br><br></font><font color="#ff8000">/* "auto" is expanded to "ASCII,JIS,UTF-8,EUC-JP,SJIS" */<br></font><font color="#0000bb">$str </font><font color="#007700">= </font><font color="#0000bb">mb_convert_encoding</font><font color="#007700">(</font><font color="#0000bb">$str</font><font color="#007700">, </font><font color="#dd0000">"EUC-JP"</font><font color="#007700">, </font><font color="#dd0000">"auto"</font><font color="#007700">);<br></font><font color="#0000bb">?></font> </font>

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.