This paper illustrates the method of PHP custom function to realize Chinese character conversion UTF8 encoding. Share to everyone for your reference, specific as follows:
The function is composed of two parts:
function Htou ($c) {
$n = (ord ($c [0]) & 0x1f) <<;
$n + = (ord ($c [1]) & 0x3f) << 6;
$n + + ord ($c [2]) & 0x3f;
return $n;
}
A string
function Utf8_unicode ($str) {
$encode = ' that hides the UTF8 format in code;
For ($i =0 $i <strlen ($STR); $i + +) {
if Ord (substr ($str, $i, 1) > 0xa0) {
$encode. = ' &# '. Htou (substr ($str, $i, 3)). '
; $i +=2;
} else {
$encode. = ' &# '. Ord ($str [$i]). '; ';
}
return $encode;
}
We can use Utf8_unicode () to convert Chinese characters and return to the UTF8 encoding of Chinese characters. This way the output page will not be garbled.
PS: Here again for you to recommend a few very practical online coding conversion tools for everyone to reference the use of:
UTF-8 Code conversion Tool:
Http://tools.jb51.net/transcoding/convutf
Online Coding Conversion Tool (UTF-8/UTF-32/PUNYCODE/BASE64):
Http://tools.jb51.net/transcoding/decode_encode_tool
Native/utf-8 Online Code conversion tool:
Http://tools.jb51.net/transcoding/native2utf8
For more information about PHP interested readers can view the site topics: "PHP coding and transcoding Operation tips Summary", "PHP object-oriented Programming Introduction Course", "PHP Mathematical Calculation Skills Summary", "PHP Array" Operation Techniques Encyclopedia, "PHP string (String) Usage summary, "PHP Data structure and algorithm tutorial", "PHP Programming Algorithm Summary", "PHP Regular Expression Usage Summary", and "PHP common database Operation skill Summary"
I hope this article will help you with the PHP program design.