Convert a Perl code to PHP

前端 未结 8 1572
粉色の甜心
粉色の甜心 2021-01-29 08:50

I need to convert the following perl function to php:

pack(\"SSA12AC4L\",
     $id,
     $loc,
     $name,
     \'ar\',
     split(/\\./, $get->getIP),
     t         


        
8条回答
  •  长发绾君心
    2021-01-29 09:30

    The problem is that php preg_split is converting it to an array. You need an unsigned char, so use

    $x = intval(implode("", preg_split('/\./','10.2.1.1', -1, PREG_SPLIT_NO_EMPTY)));
    echo pack('SSA12ACL',
         '25',
         '00001',
         '2u7wx6fd94fd',
         'f',
         $x,
         time()+(60*60));
    

    Let know how it goes.

提交回复
热议问题