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 ...
随机推荐
- [label][转载][web-design-psychology]网页设计心理
原文出处: http://mux.alimama.com/posts/1301 Tip1:信息不要同时全部展示,阶段性地向用户展示当前场景里必要的信息 设计师经常犯的错误:同时将大量信息展示给用户.不 ...
- firedac odbc sql server driver连接占线导致另一个hstmt
firedac odbc sql server driver连接占线导致另一个hstmt 原因:FDQuery.FetchOptions.Mode=fmOnDemand.好像是为了性能问题,不设置则默 ...
- 前端与HTTP
本文整理在,我的github 上.欢迎Star. 各版本的http 发展 在HTTP建立之初,主要是为了传输超文本标记语言(HTML)文档.随着时代的发展,也进行了若干次演进.下图是各个版本发布的时间 ...
- PostgreSQL 表空间
PostgreSQL 表空间 一 介绍使用表空间可以将不同的表放到不同的存储介质或不同的文件系统下,实际上是为表指定一个存储的目录.创建数据库,表,索引时可以指定表空间,将数据库,表,索引放到指定的目 ...
- Polynomial ( Arithmetic and Algebra) CGAL 4.13 -User Manual
1 Fundamentals A polynomial is either zero, or can be written as the sum of one or more non-zero ter ...
- C#基础笔记(第二十二天)
1.单例模式1)将构造函数私有化2)提供一个静态方法,返回一个对象3)创建一个单例 2.XML可扩展的标记语言 HTMLXML:存储数据 不是单独.net的东西,是一个单独的,JAVA什么的都也用不需 ...
- PHP header函数设置http报文头示例详解以及解决http返回头中content-length与Transfer-Encoding: chunked的问题
最近在服务器上,多媒体与设备(摄像头)对接的时候,总是发生错误导致设备崩溃,抓包发现响应头不对,没有返回length,使得摄像头立即崩溃.找了一下资料,改了一下响应头就好了. //定义编码 heade ...
- DOM学习日记1
1.通过 id 查找 HTML 元素 var x=document.getElementById("intro"); 2.通过标签名查找 HTML 元素本例查找 id=" ...
- 【OCP-12c】CUUG 071题库考试原题及答案解析(15)
15.(6-24)choose the best answerExamine the structure of the MEMBERS table:You want to display detail ...
- Hibernate 框架学习
什么是hibernate框架? 1.它是应用在javaee 三层架构中的dao层 它的底层就是JDBC 它对JDBC进行了封装,好处就是不用写jdbc的代码,和sql语句,它是一个开源的轻量级框架,现 ...