PHP 中关于ord($str)>0x80的详细说明
GBK简体字符集的编码是同时用1个字节和2个字节来表示的。当高位是0x00~0x7f时,为一个字节,高位为0x80以上时用2个字节表示"
注:括号里面都是2进制
当你发现一个字节的内容大于0x7f,那它肯定是个(跟另外一个字节拼凑成一个)汉字,如何判断肯定大于0x7f呢?
0x7f(1111111)后面一个数就是0x80(10000000),所以想要大于0x7f,这个字节的最高位都肯定是1,我们只需要判断这个最高位是否为1就行了。
判断方法:
位与(相同的位都是1的才为1,否则为0):
如:要判断一个数的第三位是否是1,只要跟4(100)位与,判断一个数的第2位是否为1就跟2(10)位与.
同理判断第八位是否为1只要跟(10000000)也就是0x80位与了.
这里为什么不用>0x7f,php可能还行,但在其他强类型语言里面,1个字节的最高位用来标示负数,一个负数肯定不可能大于0x7f(最大的整数)
再举个例子:
a的assic码是97(1100001)
A的assic码是65(1000001)
b的assic码是98(1100010)
b的assic码是66(1000010)
发现一个规律:一个a-z的字母,只要是小写字母,第六位肯定是1,我们可以用这个来判断大小写:
这时候只要跟用以个字母跟0x20(100000)来位与判断:
复制代码 代码如下:
if(ord($a)&0x20){
//大写
}
如何把所有字母改成大写?第六位的1改成0就行了:
复制代码 代码如下:
$a='a';
$a = chr(ord($a)&(~0x20));
echo $a;

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Validator can be created by adding the following two lines in the controller.
