note 42038 modified in function.bin2hex by aidan
| From: | aidan@php.net | Date: | Thu, 03 Jun 2004 08:27:41 +0000 |
| Subject: | note 42038 modified in function.bin2hex by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-70773@lists.php.net to get a copy of this message | ||
hexdump() is a fantastic function for "dumping" packets or binary output from servers. See
the below link for more information.
http://ircphp.com/~imho/?file=function.hexdump.php
--was--
hexdump() is a fantastic function for "dumping" packets or binary output from servers. See
the below link for more information.
http://ircphp.com/~imho/?file=function.hexdump.php
A more simple version, bin2hex_string(), is a simple function to convert strings to readable hex
data.
<?php
function bin2hex_string ($data)
{
// Properly converts a binary string to a hexidecimal string
function bin2hex_nibble ($nibble)
{
// binary to hexidecimal, then uppercase, then 0 pads
return sprintf("%02s", strtoupper(bin2hex($nibble)));
}
// Explodes, applies bin2hex_nibble, then implodes with spacing.
return implode(' ', array_map('bin2hex_nibble', str_split($data)));
}
?>
Usage example:
<?php
$binarystr= "\xFF\xFF\xFF\xFF";
print bin2hex_string($binarystr);
?>
Output:
FF FF FF FF
http://www.php.net/manual/en/function.bin2hex.php