Good day,

I can not seem to get the "h" or "H" options to work at all with unpack().

I'm pretty sure that I have this right, although the documentation for this
function is bit sparse.

The code:

  print "The data has been encoded (".strlen($varbind)." bytes in size).";

  print "Hex: <PRE> ";
  $hex_unpacked = unpack( "H*" , $varbind );
  for ( $i=1 ; $i <= sizeof($hex_unpacked) ; $i++) {
    print $hex_unpacked[$i] . "|";
  print "\n". sizeof($hex_unpacked) . " elements unpacked.\n";
  print "</PRE>\n";

prints out:

The data has been encoded (20 bytes in size).Hex: 
1 elements unpacked.

.. for the sample binary string.  If I use "C*" instead of "H*" (to print
out characters instead of hex strings) then I get the expected result:

The data has been encoded (20 bytes in size).Hex: 
20 elements unpacked.

Now, I can work around this problem by combining sprintf with the "C*"
format to format the characters into hex strings.  But, if this is a bug
then it should be addressed.

Alternatively, if unpack() isn't supposed to support all of the options of
pack() (such as "H" and "h") then the documentation should state which
options it can support.

Is this a bug, or have I just missed something?

Darren Gamble
Planner, Regional Services
Shaw Cablesystems GP
630 - 3rd Avenue SW
Calgary, Alberta, Canada
T2P 4L4
(403) 781-4948

PHP General Mailing List (
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to