<pre id="bbfd9"><del id="bbfd9"><dfn id="bbfd9"></dfn></del></pre>

          <ruby id="bbfd9"></ruby><p id="bbfd9"><mark id="bbfd9"></mark></p>

          <p id="bbfd9"></p>

          <p id="bbfd9"><cite id="bbfd9"></cite></p>

            <th id="bbfd9"><form id="bbfd9"><dl id="bbfd9"></dl></form></th>

            <p id="bbfd9"><cite id="bbfd9"></cite></p><p id="bbfd9"></p>
            <p id="bbfd9"><cite id="bbfd9"><progress id="bbfd9"></progress></cite></p>
            php語言

            php實現utf-8轉unicode函數分享

            時間:2025-04-09 19:19:14 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 >= 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實現utf-8轉unicode函數分享】相關文章:

            PHP如何實現Unicode和Utf-8編碼相互轉換07-28

            php字符轉URL地址的函數06-12

            分享php過濾XSS攻擊的函數05-21

            php制作unicode解碼工具08-02

            php實現求相對時間函數11-06

            PHP與UTF-8的最佳實踐09-15

            淺析PHP中的UNICODE編碼與解碼10-23

            php使用ftp函數實現簡單上傳功能10-31

            php自定義函數實現漢字分割替換06-01

                    <pre id="bbfd9"><del id="bbfd9"><dfn id="bbfd9"></dfn></del></pre>

                    <ruby id="bbfd9"></ruby><p id="bbfd9"><mark id="bbfd9"></mark></p>

                    <p id="bbfd9"></p>

                    <p id="bbfd9"><cite id="bbfd9"></cite></p>

                      <th id="bbfd9"><form id="bbfd9"><dl id="bbfd9"></dl></form></th>

                      <p id="bbfd9"><cite id="bbfd9"></cite></p><p id="bbfd9"></p>
                      <p id="bbfd9"><cite id="bbfd9"><progress id="bbfd9"></progress></cite></p>
                      飘沙影院