php.net |  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"];
else
  $encoded .= "-";

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

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

</script>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-03-20 05:45 UTC] stas@php.net
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-2019 The PHP Group
All rights reserved.
Last updated: Mon May 27 02:01:26 2019 UTC