php专区

 首页 > php专区 > PHP应用 > 常用功能 > php中utf-8转unicode

php中utf-8转unicode

分享到:
【字体:
导读:
          public function utf8_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 = or...

public function utf8_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);
}
分享到:
php 实现多线程
通过php的Socket方式实现php程序的多线程。php本身是不支持多线程的,那么如何在php中实现多线程呢?可以想一下,WEB服务器本身都是支持多线程的。每一个访问者,当访问WEB页面的时候,都将调用新的线程,通过这一点我们可以利用WEB服务器自身的线程来解决PHP不支持多线程的问题。     下面给出通过 fsockopen() 建...
PHP链式操作输出excel(csv)
工作中经常会遇到产品运营让导出一些简单的比较规范的数据,这时候要是有一个简单的方法可以用就简单多了。下面是我的一个输出简单的excel(csv)的方法类,用到了链式操作。说到链式操作,在jquery中可能经常用到,是不是也感觉到链式操作用起来很爽,我们也在这个类中实现下链式操作。 其实链式操作很简单的,就是在...
  •         php迷,一个php技术的分享社区,专属您自己的技术摘抄本、收藏夹。
  • 在这里……