PHP utf-8 unicode,phputf-8 to unicode_php tutorial

Source: Internet
Author: User

PHP utf-8 to Unicode,phputf-8 to Unicode


 Public functionUtf8_unicode ($str) {    $unicode=Array(); $values=Array(); $lookingFor= 1;  for($i= 0;$i<strlen($str);$i++ ) {        $thisValue=Ord($str[$i ] ); if($thisValue<Ord(' A ') ) {            //Exclude 0-9            if($thisValue>=Ord(' 0 ') &&$thisValue<=Ord(' 9 ')) {                 // Number                 $unicode[] =CHR($thisValue); }            Else {                 $unicode[] = '%'.Dechex($thisValue); }        } Else {            if($thisValue< 128) {                $unicode[] =$str[$i ]; } Else {                if(Count($values) = = 0 ) {                    $lookingFor= ($thisValue< 224)? 2:3; }                $values[] =$thisValue; if(Count($values) ==$lookingFor ) {                    $number= ($lookingFor= = 3)?                        ( ( $values[0]% 16) * 4096) + (($values[1]% 64) * 64) + ($values[2]% 64):                        ( ( $values[0]% 32) * 64) + ($values[1]% 64 ); $number=Dechex($number); $unicode[] = (strlen($number) ==3)? " \u0 ".$number: "\u".$number; $values=Array(); $lookingFor= 1; } //if}//if        }    } // for    return implode("",$unicode);}

Reference article: Http://randomchaos.com/documents/?source=php_and_unicode

http://www.bkjia.com/PHPjc/924849.html www.bkjia.com true http://www.bkjia.com/PHPjc/924849.html techarticle php utf-8 to Unicode,phputf-8 to Unicode public function Utf8_unicode ($str) {$unicode = array (); $values = Array (); $l Ookingfor = 1; for ($i = 0; $i strlen ($STR); $i + + ...

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