The Ord () function of the PHP string is used

Source: Internet
Author: User
Tags ord

  • (PHP 4, PHP 5, PHP 7)
  • Ord-return ASCII value of character
  • Ord-the ASCII value of the returned character
ord($string)//Returns the ASCII value of the first character of string.//返回字符串 string 第一个字符的 ASCII 码值。//This function complements chr().//该函数是 chr() 的互补函数。
    • A character.
    • a character.
Return Values
    • Returns the ASCII value as an integer.
    • Returns the ASCII value of an integral type.
<?php/*** Created by Phpstorm.* User:zhangrongxiang* DATE:2018/2/18* Time: PM 9:43 */$str=' abcdef '; for ( $i=0; $i<strlen( $str ); $i++){Echo $str[ $i ].' : '.Ord( $str{$i}).Php_eol;}/** a:97* b:98* c:99* d:100* e:101* f:102 */Echo Ord( ' A ' ).Php_eol;//97Echo Ord( ' B ' ).Php_eol;//98functionOrdutf8( $string,&$offset ){$code=Ord( substr( $string, $offset, 1 ) );    $bytesnumber=0;    if ( $code>= - ){//otherwise 0xxxxxxx        if ( $code<224 ){$bytesnumber=2;}//110xxxxx        Else if ( $code< - ){$bytesnumber=3;}//1110xxxx        Else if ( $code<248 ){$bytesnumber=4;}//11110xxx        $codetemp=$code-192-( $bytesnumber>2 ?  + : 0 )-( $bytesnumber>3 ?  - : 0 );         for ( $i=2; $i<=$bytesnumber; $i++){$offset++;            $code 2=Ord( substr( $string, $offset, 1 ) )- -;        //10xxxxxx            $codetemp=$codetemp* -+$code 2;}$code=$codetemp;}$offset+=1;    if ( $offset>=strlen( $string ) ){$offset= -1;}return $code;}$text="China??";$offset=0; while ( $offset>=0 ){//0:20013    //3:22269    //6:128516    Echo $offset.": ". Ordutf8( $text, $offset ).Php_eol;}functionUniord( $u ){$k=mb_convert_encoding( $u, ' Ucs-2le ', ' UTF-8 ' );    $k 1=Ord( substr( $k, 0, 1 ) );    $k 2=Ord( substr( $k, 1, 1 ) );        return $k 2* the+$k 1;}EchoUniord( "Medium" ).Php_eol;//20013EchoUniord( "Country" ).Php_eol;//22269//errorEchoUniord( '??' ).Php_eol;//63
All rights reserved

The Ord () function of the PHP string is used

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