Heim  >  Artikel  >  Backend-Entwicklung  >  php编码转换方法举例

php编码转换方法举例

WBOY
WBOYOriginal
2016-07-25 08:53:52757Durchsuche
  1. $content = iconv("gbk", "utf-8", $content); //第一种简单易用
  2. $content = mb_convert_encoding($content, "utf-8", "gbk");//第二种避免出现意外
复制代码

//发现iconv在转换字符”—”到gb2312时会出错,如果没有ignore参数,所有该字符后面的字符串都无法被保存。不管怎么样,这个”—”都无法转换成功,无法输出。 另外mb_convert_encoding没有这个bug.

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

  1. $content = iconv("utf-8″,"gbk", $content); //第一种简单易用
  2. $content = mb_convert_encoding($content,"gbk","utf-8");//第二种避免出现意外
复制代码

格式参考 string iconv ( string $in_charset , string $out_charset , string $str ) string mb_convert_encoding ( string $str , string $to_encoding [, mixed $from_encoding ] )



Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn