Home > Backend Development > PHP Tutorial > 关于 php7 中 "0xFFFFFFFF" 和 0xFFFFFFFF 的问题

关于 php7 中 "0xFFFFFFFF" 和 0xFFFFFFFF 的问题

WBOY
Release: 2016-06-06 20:13:06
Original
2143 people have browsed it

<code>$t1 = 0x3FFFFFFF & (1 * (0xd5b42e11));
$t2 = 0x3FFFFFFF & (1 * ("0xd5b42e11"));

var_dump($t1,$t2);</code>
Copy after login
Copy after login

以上代码在 php7(不含)以下平台的值为:

<code>int(364129809)
int(364129809)</code>
Copy after login
Copy after login

而在 php7的值为:

<code>int(364129809)
int(0)</code>
Copy after login
Copy after login

请问,在 php7的环境下,应该如何处理 0x.$str 使它同上面值一样呢?

回复内容:

<code>$t1 = 0x3FFFFFFF & (1 * (0xd5b42e11));
$t2 = 0x3FFFFFFF & (1 * ("0xd5b42e11"));

var_dump($t1,$t2);</code>
Copy after login
Copy after login

以上代码在 php7(不含)以下平台的值为:

<code>int(364129809)
int(364129809)</code>
Copy after login
Copy after login

而在 php7的值为:

<code>int(364129809)
int(0)</code>
Copy after login
Copy after login

请问,在 php7的环境下,应该如何处理 0x.$str 使它同上面值一样呢?

PHP7开始,含十六进制字符串不再被认为是数字
如果非要检测字符串是否含十六进制数字,官方建议的代码是

<code><?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)
?></code>
Copy after login

针对你的问题就应该改成

<code>$t1 = 0x3FFFFFFF & (1 * (0xd5b42e11));
$t2 = 0x3FFFFFFF & (1 * (filter_var("0xd5b42e11", FILTER_VALIDATE_INT, FILTER_FLAG_ALLOW_HEX)));

var_dump($t1,$t2);</code>
Copy after login
Related labels:
php
source:php.cn
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