ord

  • (PHP 4, PHP 5, PHP 7)
  • ord — Return ASCII value of character
  • ord — 返回字符的 ASCII 码值

Description

int ord ( string $string )
//Returns the ASCII value of the first character of string.
//返回字符串 string 第一个字符的 ASCII 码值。
//This function complements chr().
//该函数是 chr() 的互补函数。

Parameters

string

  • A character.
  • 一个字符。

Return Values

  • Returns the ASCII value as an integer.
  • 返回整型的 ASCII 码值。

Examples

<?php
/**
* Created by PhpStorm.
* User: zhangrongxiang
* Date: 2018/2/18
* Time: 下午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;//97
echo ord( 'b' ) . PHP_EOL;//98 function ordutf8( $string, &$offset ) {
$code = ord( substr( $string, $offset, 1 ) );
$bytesnumber = 0;
if ( $code >= 128 ) { //otherwise 0xxxxxxx
if ( $code < 224 ) {
$bytesnumber = 2;
} //110xxxxx
else if ( $code < 240 ) {
$bytesnumber = 3;
} //1110xxxx
else if ( $code < 248 ) {
$bytesnumber = 4;
} //11110xxx
$codetemp = $code - 192 - ( $bytesnumber > 2 ? 32 : 0 ) - ( $bytesnumber > 3 ? 16 : 0 );
for ( $i = 2; $i <= $bytesnumber; $i ++ ) {
$offset ++;
$code2 = ord( substr( $string, $offset, 1 ) ) - 128; //10xxxxxx
$codetemp = $codetemp * 64 + $code2;
}
$code = $codetemp;
}
$offset += 1;
if ( $offset >= strlen( $string ) ) {
$offset = - 1;
} return $code;
} $text = "中国

PHP之string之ord()函数使用的更多相关文章

  1. php 截取中文字符串 - ord()函数 0xa0...

    在ASCII中,0xa0表示汉字的开始 其中php中的一个函数ord()函数 此函数功能返回一个字符的askii码值: 如ord('A')=65; <?php function GBsubstr ...

  2. [PHP] chr和ord函数实现字符串和ASCII码互转

    chr和ord函数是用来字符串和ASCII码互转的.  ASCII码是计算机所能显示字符的编码,它的取值范围是0-255,其中包括标点.字母.数字.汉字等.在编程过程中,经常把指定的字符转化为ASCI ...

  3. php pack、unpack、ord 函数使用方法

    string pack ( string $format [, mixed $args [, mixed $... ]] ) Pack given arguments into a binary st ...

  4. 用php的chr和ord函数实现字符串和ASCII码互转

    http://shenyongqang.blog.163.com/blog/static/22439113201002941856838/ chr和ord函数是用来字符串和ASCII码互转的. ASC ...

  5. python中的ord函数

    chr().unichr()和ord() chr()函数用一个范围在range(256)内的(就是0-255)整数作参数,返回一个对应的字符.unichr()跟它一样,只不过返回的是Unicode字符 ...

  6. PHP之string之addcslashes()函数使用

    addcslashes (PHP 4, PHP 5, PHP 7) addcslashes - Quote string with slashes in a C style addcslashes - ...

  7. php的ord函数——解决中文字符截断问题

    php的ord函数——解决中文字符截断问题 分类: PHP2014-11-26 12:11 1033人阅读 评论(0) 收藏 举报 utf8字符截取 函数是这样定义的: int ord ( strin ...

  8. php ord()函数 语法

    php ord()函数 语法 作用:返回字符串的首个字符的 ASCII 值.直线电机生产厂家 语法:ord(string) 参数: 参数 描述 string 必须,要从中获得ASCII值的字符串 说明 ...

  9. PHP ord() 函数

    实例 返回 "h" 的 ASCII值: <?php高佣联盟 www.cgewang.comecho ord("h")."<br>&q ...

随机推荐

  1. Web 应用简单测试方案

    测试:一定要分阶段测试,先确定入队列成功,再测试队列的执行是否成功. 功能点: 1. 翻页2. 加精3. 置顶4. 帖子浏览量(PV)5. 发帖6. 回复7. 评论 8. crontab 脚本 @20 ...

  2. [label][JavaScript]闭包阅读笔记

    原文链接来源:                       http://www.ruanyifeng.com/blog/2009/08/learning_javascript_closures.ht ...

  3. Oracle Inventory Management Application Program Interface ( APIs) (Doc ID 729998.1)

    In this Document Goal Solution References APPLIES TO: Oracle Inventory Management - Version 12.0.0 a ...

  4. Lucene的数值索引以及范围查询

    对文本搜索引擎的倒排索引(数据结构和算法).评分系统.分词系统都清楚掌握之后,本人对数值索引和搜索一直有很大的兴趣,最近对Lucene对数值索引和范围搜索做了些学习,并将主要内容整理如下: 1. Lu ...

  5. 使用Jenkins容器构建时,关于maven项目settings.xml的位置

    切记切记:必须要放在 /root/.m2/settings.xml,要不然Jenkins容器中执行mvn命令时settings会不生效

  6. Tomcat启动报错Invalid character found in method name. HTTP method names must be tokens

    1.tomcat服务器需配置三个端口才能启动,安装时默认启用了这三个端口,当要运行多个tomcat服务时需要修改这三个端口,不能相同. 端口一: 修改http访问端口(默认为8080端口),配置文件为 ...

  7. Selenium框架切换-----Selenium快速入门(七)

    上一篇说了窗口的切换,本篇说说框架的切换. 切换框架:是指切换html中的iframe标签元素或者frame标签元素,注意,并不包括frameset 以下是常用的方法: 方法 说明 WebDriver ...

  8. 关于My Sql update语句不能用子查询的解决办法

    在使用My Sql数据库语法操作update时,第一时间想到的是一下写法: UPDATE purchase_request_detail SET convert_to_voucher_id=, con ...

  9. .Net 数据缓存浅析

    目录 1场景出发 1.1数据请求 1.2优化改进 2缓存 3缓存进阶 3.1缓存清除 3.2有效性 3.3线程安全 4适用场景和优劣 4.1适用场景 4.2优劣 5结语 1场景出发 1.1数据请求 小 ...

  10. iOS 画图基础

    基础要点: 1,画图不可以在 ViewController 里,而是应该在一个 UIView 的子类中,比如新建一个 DrawView 继承自 UIView. 2,覆盖 UIView 的 drawRe ...