PHP custom UTF8 and cp1251 functions _php Tutorial

Source: Internet
Author: User
PHP Tutorial customizing UTF8 and cp1251 functions
When you need to convert some data from UTF8, cp1251 (Windows-1251) or cp1251 to UTF8 you must use the iconv of the system functions. Common hosting providers do not allow this feature to be used.
*/
function Cp1251_to_utf8 ($s) {
$c 209 = chr (209); $c 208 = chr (208); $c 129 = Chr (129);
for ($i =0; $i
$c =ord ($s [$i]);
if ($c >=192 and $c <=239) $t. = $c 208.CHR ($c-48);
ElseIf ($c >239) $t. = $c 209.CHR ($c-112);
ElseIf ($c ==184) $t. = $c 209. $c 209;
ElseIf ($c ==168) $t. = $c 208. $c 129;
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 ($byte 2) {
$new _c2= ($c 1&3) *64+ ($i &63);
$new _c1= ($c 1>>2) &5;
$new _i= $new _c1*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);
$byte 2=false;
}
if (($i >>5) ==6) {
$c 1= $i;
$byte 2=true;
}
}
return $out;
}

http://www.bkjia.com/PHPjc/632361.html www.bkjia.com true http://www.bkjia.com/PHPjc/632361.html techarticle PHP Tutorial Custom UTF8 and cp1251 functions when you need to convert some data from UTF8, cp1251 (Windows-1251) or cp1251 to UTF8 you must use the system functions of iconv. Common host provider forbid ...

  • Related Article

    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.