您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

PHP如何把字符串改成UTF8?

2024/5/14 7:17:51发布43次查看
php如何把字符串改成utf8?
在php中可以使用“iconv()”函数把字符串改成utf8,该函数作用是将字符串按要求的字符编码来转换,其语法为“iconv(in,out,str)”,使用时将in设置为字符串的编码,out设置为utf8,str设置为要转换的字符串即可。
转化示例
$str = "123456789";$str = iconv('ascii', 'utf8', $str);
使用示例
<?php//some german$utf8_sentence = 'weiß, goldmann, göbel, weiss, göthe, goethe und götz';//uksetlocale(lc_all, 'en_gb');//transliterate$trans_sentence = iconv('utf-8', 'ascii//translit', $utf8_sentence);//gives [weiss, goldmann, gobel, weiss, gothe, goethe und gotz]//which is our original string flattened into 7-bit ascii as//an english speaker would do it (ie. simply remove the umlauts)echo $trans_sentence . php_eol;//germanysetlocale(lc_all, 'de_de');$trans_sentence = iconv('utf-8', 'ascii//translit', $utf8_sentence);//gives [weiss, goldmann, goebel, weiss, goethe, goethe und goetz]//which is exactly how a german would transliterate those//umlauted characters if forced to use 7-bit ascii!//(because really ä = ae, ö = oe and ü = ue)echo $trans_sentence . php_eol;?>
<?php$tab = array("utf-8", "ascii", "windows-1252", "iso-8859-15", "iso-8859-1", "iso-8859-6", "cp1256");$chain = "";foreach ($tab as $i) { foreach ($tab as $j) { $chain .= " $i$j ".iconv($i, $j, "$my_string"); } }echo $chain;?>
推荐教程:《php教程》
以上就是php如何把字符串改成utf8?的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product