php - 恢复解压 ('C*' , "string")

标签 php pack unpack

我想知道如何扭转这个 unpack执行以下功能。我认为 pack函数能够反转什么unpack执行,但我不确定。

首先我有一个简单的字符串,在解包后我将有一个字节数组表示这样的字符串。现在我想知道如何将这样的数组反转回原始字符串。

<?php
$array = unpack('C*', "odd string");
/*Output: Array
(
    [1] => 111
    [2] => 100
    [3] => 100
    [4] => 32
    [5] => 115
    [6] => 116
    [7] => 114
    [8] => 105
    [9] => 110
    [10] => 103
)*/

$string = pack("which format here?", $array);

echo $string;
#Desired Output: odd string
?>

谢谢。

最佳答案

你应该使用 call_user_func_array还原 unpack('C*', “string”),像这样:

call_user_func_array('pack', array_merge(array('C*'), $array )))

关于php - 恢复解压 ('C*' , "string"),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18357008/

相关文章:

php - 登录实时服务器时出现 CSS 和导航栏问题

wpf - Powershell 包 uri 对象

python - 值太多,无法解压混淆矩阵

PHP - 读取8位整数

qt - 如何解压 QByteArray 中的 32 位整数?

php - 将多个 csv 文件导入 mysql 表

php - 如何从字符串中删除 'em' 破折号?

php - 结合两个mysql结果

c - #Pragma pack 编译时发出警告

PHP 字符串到 "unsigned long"(来自 C++)