脚本宝典收集整理的这篇文章主要介绍了在PHP中将utf8转换为latin1. 255以上的所有字符都转换为char引用,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
示例:我想将文字转换为
hello é β 水
成
hello é β 水
我在PHP中做这一切.我尝试了内置函数,iconv,整洁和组合,仍然无法获得可靠的解决方案.
这是我到目前为止所拥有的
// convert any characters fount in the entITy table into HTML entities // do not double encode entities,do not mess with quotes // use UTF-8 as character encoding because the page submits UTF-8 $str = htmlentities($str,ENT_NOQUOTES,'UTF-8',false); //PRint $str."\n"; // convert text From UTF-8 to ISO-8859-1,// characters that cannot be converted will be converted to ? $str = utf8_decode($str); //print $str."\n"; // make string XML valid. // mainly it converts text entities into numeric entities. $opts = array( "output-xhtml" => true,"output-xml" => true,"show-body-only" => true,"numeric-entities" => true,"wrap" => 0,"indent" => false,"char-encoding" => 'latin1' ); $tidy = tidy_parse_string($str,$opts,'latin1'); tidy_clean_repair($tidy); $str = tidy_get_output($tidy); //print $str."\n";
$convmap= array(0x0100,0xFFFF,0xFFFF); $encutf= mb_encode_numericentity($utf,$convmap,'UTF-8'); $iso= utf8_decode($encutf);
(这不会触及<,&,“等,所以你可能也需要预先使用htmlsPEcialchars().)
以上是脚本宝典为你收集整理的在PHP中将utf8转换为latin1. 255以上的所有字符都转换为char引用全部内容,希望文章能够帮你解决在PHP中将utf8转换为latin1. 255以上的所有字符都转换为char引用所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。