Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Detailed description of ord ($str) & gt;0x80 in PHP

2025-03-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces the relevant knowledge of "ord ($str) > 0x80 in PHP". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

The encoding of the GBK simplified character set is represented by both 1 byte and 2 bytes. When the high bit is 0x00~0x7f, it is one byte, and when the high bit is more than 0x80, it is represented by 2 bytes. "

Note: the brackets are all binary.

When you find that the content of a byte is larger than 0x7f, it must be a Chinese character (pieced together with another byte). How can you tell that it must be larger than 0x7f?

The number after 0x7f (1111111) is 0x80 (10000000), so if you want to be greater than 0x7f, the highest bit of this byte must be 1, we just need to determine whether the highest bit is 1 or not.

The method of judgment:

Bit and (only 1 if the same bit is 1, otherwise 0):

For example, to determine whether the third bit of a number is 1, just follow the sum of 4 (100) bits, and determine whether the second bit of a number is 1, followed by 2 (10) bits and.

Similarly, to judge whether the eighth place is 1 or not, as long as it follows (10000000), that is, the 0x80 position and.

Why not use > 0x7fPowerPhp may be OK, but in other strongly typed languages, the highest bit of 1 byte is used to mark a negative number, and a negative number certainly cannot be greater than 0x7f (the largest integer).

Another example:

The ASIC code of an is 97 (1100001)

The ASIC code of An is 65 (1000001).

The ASIC code of b is 98 (1100010)

The ASIC code of b is 66 (1000010).

We found a rule: as long as a letter of amurz is lowercase, the sixth place must be 1. We can use this to judge case.

At this point, just follow the letter with 0x20 (100000) to position and judge:

The copy code is as follows:

If (ord ($a) & 0x20) {

/ / capitalize

}

How to change all letters to uppercase? Just change the number one in the sixth place to zero:

The copy code is as follows:

$axianga'

A = chr (ord ($a) & (~ 0x20))

Echo $a

This is the end of "detailed description of ord ($str) > 0x80 in PHP". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report