PHP Warning: pack (): Type H: Incorrect r hexadecimal error

Possible duplicate:
pack () in php. Hexadecimal Warning

I use the apple push notification service, and to send a notification, you need to create the message in binary format. I got the following errors for the line below:

Warning: pack (): Type H: illegal hexadecimal digit r

Warning: pack (): Type H: illegal hexadecimal digit y

Note. Converting an array to a string in C: \ xampp \ htdocs \ firecom \ FireComAPNS.php on line 130

Here's the line of code that throws an error:

$msg = chr(0).pack('n', 32).pack('H*', $devicetoken).pack('n',strlen($payload)) . $payload; 

and

 $devicetoken=773f5436825a7115417d3d1e036da20e806efeef547b7c3fe4da724d97c01b30 

I searched the Internet many times, but I have no idea how to mess around with binary code, any help on what happens will be greatly appreciated!

+7
source share
1 answer

Try this function for php <5.4.0

 function hex2bin($hexdata) { $bindata=""; for ($i=0;$i<strlen($hexdata);$i+=2) { $bindata.=chr(hexdec(substr($hexdata,$i,2))); } return $bindata; } 
0
source

All Articles