Heim >Backend-Entwicklung >PHP-Tutorial >php字符串怎么转utf-8编码

php字符串怎么转utf-8编码

PHPz
PHPzOriginal
2016-06-06 20:21:164111Durchsuche

php字符串转utf-8编码的方法:首先通过“mb_detect_encoding”函数检测字符的编码;然后使用“mb_convert_encoding”函数转换字符的编码即可。

php字符串怎么转utf-8编码

php字符串怎么转utf-8编码?

在使用mb_convert_encoding时要先知道字符编码,如果编码错误就会乱码,使用mb_detect_encoding自动识别字符串编码,并转换成国际标准编码utf-8编码。

<?php
$encode = mb_detect_encoding($str, array("ASCII",&#39;UTF-8&#39;,"GB2312","GBK",&#39;BIG5&#39;,&#39;LATIN1&#39;));
if($encode != &#39;UTF-8&#39;){
    $name = mb_convert_encoding($name, &#39;UTF-8&#39;, $encode);
}

更多相关知识,请访问PHP中文网

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
Vorheriger Artikel:php 上传arm转码mp3 返回访问链接Nächster Artikel:多维数组排序