Php custom UTF8 and cp1251 function _ PHP Tutorial

Source: Internet
Author: User
Php custom UTF8 and cp1251 functions. Php Tutorial custom utf8 and cp1251 functions when you need to convert some data from utf8, cp1251 (window-1251) or cp1251 to utf8 you must use system function iconv. Common host service providers do not allow php tutorials to customize utf8 and cp1251 functions
When you need to convert some data from utf8, cp1251 (window-1251) or cp1251 to utf8 you must use the system function iconv. Common host service providers do not allow this feature.
*/
Function cp1251_to_utf8 ($ s ){
$ C209 = chr (209); $ c208 = chr (208); $ c129 = chr (129 );
For ($ I = 0; $ I $ C = ord ($ s [$ I]);
If ($ c> = 192 and $ c <= 239) $ t. = $ c208.chr ($ C-48 );
Elseif ($ c> 239) $ t. = $ c209.chr ($ C-112 );
Elseif ($ c = 184) $ t. = $ c209. $ c209;
Elseif ($ c = 168) $ t. = $ c208. $ c129;
Else $ t. = $ s [$ I];
}
Return $ t;
}

Function utf8_to_cp1251 ($ s)
{
For ($ c = 0; $ c {
$ I = ord ($ s [$ c]);
If ($ I <= 127) $ out. = $ s [$ c];
If ($ byte2 ){
$ New_c2 = ($ c1 & 3) * 64 + ($ I & 63 );
$ New_c1 = ($ c1> 2) & 5;
$ New_ I = $ new_c1 x 256 + $ new_c2;
If ($ new_ I = 1025 ){
$ Out_ I = 168;
} Else {
If ($ new_ I = 1105 ){
$ Out_ I = 184;
} Else {
$ Out_ I = $ new_i-848;
}
}
$ Out. = chr ($ out_ I );
$ Byte2 = false;
}
If ($ I> 5) = 6 ){
$ C1 = $ I;
$ Byte2 = true;
}
}
Return $ out;
}

Custom utf8 and cp1251 functions when you need to convert some data from utf8, cp1251 (window-1251) or cp1251 to utf8 you must use the system function of iconv. Common host service providers do not allow...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.