Home > Backend Development > PHP7 > Regarding the processing of hexadecimal strings in PHP7

Regarding the processing of hexadecimal strings in PHP7

藏色散人
Release: 2023-02-18 09:02:01
forward
1945 people have browsed it

This article is from the PHP7 tutorial column to introduce to you the problems of "0xFFFFFFFF" and 0xFFFFFFFF in php7. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

Specific question:

$t1 = 0x3FFFFFFF & (1 * (0xd5b42e11));
$t2 = 0x3FFFFFFF & (1 * ("0xd5b42e11"));
var_dump($t1,$t2);
Copy after login

The value of the above code in php7 (not included) and the following platforms is:

int(364129809)
int(364129809)
Copy after login

And the value in php7 is:

int(364129809)
int(0)
Copy after login

Excuse me, in the php7 environment, how should I deal with 0x.$str to make it the same as the above value?

Solution:

Starting from PHP7, strings containing hexadecimal are no longer considered numbers

If you have to check whether the string Containing hexadecimal numbers, the officially recommended code is

<?php
$str = "0xffff";
$int = filter_var($str, FILTER_VALIDATE_INT, FILTER_FLAG_ALLOW_HEX);
if (false === $int) {
    throw new Exception("Invalid integer!");
}
var_dump($int); // int(65535)
?>
Copy after login

which should be changed to

$t1 = 0x3FFFFFFF & (1 * (0xd5b42e11));
$t2 = 0x3FFFFFFF & (1 * (filter_var("0xd5b42e11", FILTER_VALIDATE_INT, FILTER_FLAG_ALLOW_HEX)));
var_dump($t1,$t2);
Copy after login
for the above problems.

The above is the detailed content of Regarding the processing of hexadecimal strings in PHP7. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template