Ord
- (PHP 4, PHP 5, PHP 7)
- Ord-return ASCII value of character
- Ord-the ASCII value of the returned character
Description
ord($string)//Returns the ASCII value of the first character of string.//返回字符串 string 第一个字符的 ASCII 码值。//This function complements chr().//该函数是 chr() 的互补函数。
Parametersstring
- A character.
- a character.
Return Values
- Returns the ASCII value as an integer.
- Returns the ASCII value of an integral type.
Examples
<?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
See
- http://php.net/manual/en/function.ord.php
All rights reserved
The Ord () function of the PHP string is used