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

php编码转换函数

WBOY
WBOYOriginal
2016-06-13 10:38:42867browse

        一般情况下用 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>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn