I need to convert the following perl function to php:
pack("SSA12AC4L",
$id,
$loc,
$name,
'ar',
split(/\./, $get->getIP),
time+(60*60);
I use the following code (to test) in PHP:
echo pack("SSA12AC4L",
'25',
'00001',
'2u7wx6fd94fd',
'f',
preg_split('/\./','10.2.1.1', -1, PREG_SPLIT_NO_EMPTY),
time()+(60*60));
But I’m getting the following error:
Warning: pack() [function.pack]: Type C: too few arguments in D:\wamp\www\test.php on line 8
Any suggestions? Thanks a lot.
The problem is that the code is giving to
pack()(I am referring the the last arguments) a character, an array, and an integer. As the codeCwants 4 characters, that is the cause of the error.The code should be something like
Then, there is no reason to use
preg_split()in this case, whenexplode()can be used instead. Regular expressions should be used only when strictly necessary because the regular expression functions are slower, compared to other string functions.