function htmlEncode($text) { $encoded = ""; for( $index = 0; $index < strlen($text); $index++) { if( ord($text[$index]) <= 127 ) { switch(ord($text[$index])) { case 34: case 38: case 39: case 60: case 62: $encoded .= "" .ord($text[$index]).";"; break; default: $encoded .= $text[$index]; } } else { $char = $text[$index] . $text[$index+1]; $char = mb_convert_encoding( $char, "utf-16", "gbk"); $encoded .= "" . (ord($char[0])*256 + ord($char[1])) . ";"; $index++; } } return $encoded; } function htmlEncode($text) { $encoded = ""; for( $index = 0; $index < strlen($text); $index++) { if( ord($text[$index]) <= 127 ) { switch(ord($text[$index])) { case 34: case 38: case 39: case 60: case 62: $encoded .= "" .ord($text[$index]).";"; break; default: $encoded .= $text[$index]; } } else { $char = $text[$index] . $text[$index+1]; $char = mb_convert_encoding( $char, "utf-16", "gbk"); $encoded .= "" . (ord($char[0])*256 + ord($char[1])) . ";"; $index++; } } return $encoded; }
然后通过XML返回,这样就能够彻底杜绝乱码。
复制代码 代码如下: (编辑:焦作站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|