PHP之string之ord()函数使用
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()函数使用的更多相关文章
- php 截取中文字符串 - ord()函数 0xa0...
在ASCII中,0xa0表示汉字的开始 其中php中的一个函数ord()函数 此函数功能返回一个字符的askii码值: 如ord('A')=65; <?php function GBsubstr ...
- [PHP] chr和ord函数实现字符串和ASCII码互转
chr和ord函数是用来字符串和ASCII码互转的. ASCII码是计算机所能显示字符的编码,它的取值范围是0-255,其中包括标点.字母.数字.汉字等.在编程过程中,经常把指定的字符转化为ASCI ...
- php pack、unpack、ord 函数使用方法
string pack ( string $format [, mixed $args [, mixed $... ]] ) Pack given arguments into a binary st ...
- 用php的chr和ord函数实现字符串和ASCII码互转
http://shenyongqang.blog.163.com/blog/static/22439113201002941856838/ chr和ord函数是用来字符串和ASCII码互转的. ASC ...
- python中的ord函数
chr().unichr()和ord() chr()函数用一个范围在range(256)内的(就是0-255)整数作参数,返回一个对应的字符.unichr()跟它一样,只不过返回的是Unicode字符 ...
- PHP之string之addcslashes()函数使用
addcslashes (PHP 4, PHP 5, PHP 7) addcslashes - Quote string with slashes in a C style addcslashes - ...
- php的ord函数——解决中文字符截断问题
php的ord函数——解决中文字符截断问题 分类: PHP2014-11-26 12:11 1033人阅读 评论(0) 收藏 举报 utf8字符截取 函数是这样定义的: int ord ( strin ...
- php ord()函数 语法
php ord()函数 语法 作用:返回字符串的首个字符的 ASCII 值.直线电机生产厂家 语法:ord(string) 参数: 参数 描述 string 必须,要从中获得ASCII值的字符串 说明 ...
- PHP ord() 函数
实例 返回 "h" 的 ASCII值: <?php高佣联盟 www.cgewang.comecho ord("h")."<br>&q ...
随机推荐
- 原创:MVC 5 实例教程(MvcMovieStore 新概念版:mvc5.0,EF6.01) - 4、创建数据上下文和数据实体模型
说明:MvcMovieStore项目已经发布上线,想了解最新版本功能请登录 MVC影视(MvcMovie.cn) 进行查阅.如需转载,请注明出处:http://www.cnblogs.com/Dodu ...
- 【转发】在SQL Server中通过字段值查询存储该字段的表
-- Copyright © 2002 Narayana Vyas Kondreddi. All rights reserved. -- Purpose: To search all colu ...
- linux free命令下 cached占用很大
# 背景 使用free -h命令,展示如下: # 解决方法 先执行sync命令,同步数据 然后执行 echo 1 > /proc/sys/vm/drop_caches echo 2 > / ...
- 手动编译安装lamp之mysql
转自马哥教育的讲课文档 二.安装mysql-5.5.28 1.准备数据存放的文件系统 新建一个逻辑卷,并将其挂载至特定目录即可.这里不再给出过程. 这里假设其逻辑卷的挂载目录为/mydata,而后需要 ...
- DbMigration的使用方法
先打开:工具=>NuGet程序包管理器=>程序包管理器控制台然后输入Enable-Migrations回车然后输入Add-Migration Name回车(这里Name你可以自己命名)最后 ...
- 解决“找不到请求的 .Net Framework Data Provider。可能没有安装.”错误
问题: 这几天在装.NET 的开发环境,在装好VS2013和Oracle 11g之后,做了一个测试项目,运行调试没问题 但是涉及到数据库相关操作,如新建数据集.连接数据库等在调试的时候则会出现如下错误 ...
- Spring @SCHEDULED(CRON = "0 0 * * * ?")实现定时任务
Spring配置文件xmlns加入 xmlns:task="http://www.springframework.org/schema/task" xsi:schemaLocati ...
- spring指导的index.html在spring文件夹中的位置
- declare命令
还是围绕以下几个问题进行学习; 1.declare是什么? 2.问什么要用declare? 3.怎样使用declare? 1.declare是什么? ♦declare应用的很多,向我们各种语言都会有声 ...
- C++多线程编程一
1.C++多线程初步: #include <iostream> #include <thread> #include <Windows.h> using names ...