note 42038 added to function.bin2hex

From: Date: Fri, 30 Apr 2004 12:48:08 +0000
Subject: note 42038 added to function.bin2hex
Groups: php.notes 
Request: Send a blank email to php-notes+get-69034@lists.php.net to get a copy of this message
Below is my function to convert a binary string into a readable hexidecimal representation. Perfect for debugging stream or socket output. Function: <?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 ---- Manual Page -- http://www.php.net/manual/en/function.bin2hex.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+42038 Delete -- http://master.php.net/manage/user-notes.php?action=delete+42038&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+42038&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#69034) next »