tasoft / php-secure-int64-extension
v0.8.0
2022-03-31 15:13 UTC
Requires
- php: >=7.3
This package is auto-updated.
Last update: 2024-09-29 06:08:45 UTC
README
我创建这个包是为了处理MFRC511模块的UUID。它使用5字节ID,无法由32位系统表示。(因为树莓派是32位的。)
安装
$ cd ~
$ git clone https://github.com/tasoftch/php-secure-int64-extension.git
$ cd php-secure-int64-extension
$ phpize
$ ./configure --enable-secure-int64
$ make
$ sudo make install
这将编译您机器上的源代码。
接下来找到php.ini文件
$ php --ini
将列出扫描到的ini文件。
将以下行添加到该php.ini文件中:extension=secure_int64
<?php var_dump( extension_loaded('secure_int64') ); // Should be true
使用方法
该扩展将以下函数添加到全局作用域
sint64_array_to_string
将最大8字节的数组转换为64位有符号整数表示的字符串。uint64_array_to_string
将最大8字节的数组转换为64位无符号整数表示的字符串。sint64_string_to_array
将字符串解释为有符号64位整数值,并以数组形式返回,最高有效位(MSB)首先。uint64_string_to_array
将字符串解释为无符号64位整数值,并以数组形式返回,最高有效位(MSB)首先。
示例
<?php echo sint64_array_to_string([1]); // 1 echo sint64_array_to_string([1, 4]); // 260 echo sint64_array_to_string([0xFF, 0xFF]); // 65535 echo sint64_array_to_string([0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]); // 9223372036854775807 echo sint64_array_to_string([0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]); // -1 echo uint64_array_to_string([0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]); // 18446744073709551615 ?>