|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #9168 unpack 'h' and 'H' formats don't work
Submitted: 2001-02-07 18:56 UTC Modified: 2001-03-20 05:45 UTC
From: rusty at socrates dot berkeley dot edu Assigned:
Status: Closed Package: Strings related
PHP Version: 4.0.4pl1 OS: solaris 7
Private report: No CVE-ID: None
 [2001-02-07 18:56 UTC] rusty at socrates dot berkeley dot edu
In the following sample the variable "encoded" is zero length; an empty string.  If I change the format chars from H and h to C then it does get stuff.

<script language="php">

// 0xFF * 0xEE
$ch = 60690;

$encoded = "";

$hexn = unpack("Hz", $ch); // high nibble
if (isset($hexn["z"]))
  $encoded .= $hexn["z"];
  $encoded .= "-";

$hexn = unpack("hz", $ch); // low nibble
if (isset($hexn["z"]))
  $encoded .= $hexn["z"];
  $encoded .= "-";

echo $encoded . "<br>";
echo strlen($encoded) . "<br>";



Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-03-20 05:45 UTC]
H and h doesn't work by nibbles, only by bytes (i.e., you
cannot really do unpack("H<n>z") when n is not even.
Otherwise, if you write unpack("Hz/C"), the C whould have to
start from half-byte, which is absurd.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 13 04:01:28 2024 UTC