[英]Convert python pack to php pack
I have this python script 我有这个python脚本
b_string = pack('>hqh2sh13sh5sh3sBiiihiiiiii',
21, 0,
len(country), country,
len(device), device,
len('1.3.1'), "1.3.1",
len('Web'), "Web",
27, 0, 0,
3, 0, cid, lac,
0, 0, 0, 0)
and I want to convert it to php, this is what I came with so far 我想将其转换为php,这是我到目前为止附带的内容
$body= pack('nln2c*n13c*n5c*n3c*Ciiiniiiiii',
21, 0,
strlen($this->_mccToCountry[$this->_mcc]), $this->_mccToCountry[$this->_mcc],
strlen($this->_device), $this->_device,
strlen('1.3.1'), "1.3.1",
strlen('Web'), "Web",
27, 0, 0,
3, 0, $this->_cellId, $this->_lac,
0, 0, 0, 0);
The variables are same as those in python script, but i got this error 变量与python脚本中的变量相同,但出现此错误
PHP Warning: pack(): Type n: too few arguments in .../application/extensions/Zend-extensions/NMS/Bts.php:150 PHP警告:pack():类型n:... / application / extensions / Zend-extensions / NMS / Bts.php:150中的参数太少
The help will be very appreciated. 帮助将不胜感激。
Your parameter string is all screwed up. 您的参数字符串都已拧紧。 You indicate in places that you are going to pass 2, 5, 3 and 13 shorts, but only provide one each time.
您在某些地方表示要通过2、5、3和13次短裤,但每次只能提供一次。 You indicate that you are going to provide a series of characters but then you provide a
NUL
terminated string. 您指示要提供一系列字符,但随后提供
NUL
终止的字符串。 You indicate that you will be providing an unsigned char but don't provide one. 您表示将提供一个未签名的字符,但不提供一个。 Try this format string instead:
尝试使用以下格式字符串:
'nlna*na*na*na*i3ni6'
Another option is to use serialize
and deserialize
instead. 另一种选择是改为使用
serialize
和deserialize
serialize
。 Not sure if it matters to you that the data is packed into bytes or serialized into strings. 不确定数据打包成字节还是序列化为字符串对您来说是否重要。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.