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...