I have this python script
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
$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
PHP Warning: pack(): Type n: too few arguments in …/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. You indicate that you are going to provide a series of characters but then you provide a
NULterminated string. You indicate that you will be providing an unsigned char but don’t provide one. Try this format string instead:Another option is to use
serializeanddeserializeinstead. Not sure if it matters to you that the data is packed into bytes or serialized into strings.