PHP 中,pack 与 unpack 的使用示例。

= - =

论坛:https://laravel-workerman.iwnweb.com/d/11-php-pack-unpack

pack 文档:https://www.php.net/manual/en/function.pack.php
unpack 文档:https://www.php.net/manual/en/function.unpack.php
PHP中pack、unpack的详细用法:https://segmentfault.com/a/1190000008305573

在线示例:https://sandbox.onlinephpfunctions.com/c/56feb

<?php

$encodeFormat = 'a6N';
$decodeFormat = 'a6random_str/Ntimestamp';
$data = [
    uniqid(),
    time()
];

$res = pack($encodeFormat, ...$data);

$encode = base64_encode($res);
var_dump($encode);

$data = unpack($decodeFormat, base64_decode($encode));
var_dump($data);

example

152 1 2
1个评论

liziyu

这个必须收藏,后面可能会用了。谢谢

  • 暂无评论

= - =

880
积分
0
获赞数
0
粉丝数
2021-12-15 加入
🔝