note 15056 added to function.bin2hex.php
| From: | tightcode at hotmail dot com | Date: | Sun, 26 Aug 2001 00:05:46 +0000 |
| Subject: | note 15056 added to function.bin2hex.php | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-17147@lists.php.net to get a copy of this message | ||
I was just browsing the above and with a little modification,
came up with the following which I believe to be more flexible:
function bin2hex($data) {
$corrected = ereg_replace("[^0-9a-fA-F]","",$data);
return pack("H".strlen($corrected),$corrected);
}
This will make sure that whatever you pass, even if it is padded
at the extremeties or between pairs, should return the desired data.
http://www.php.net/manual/en/function.bin2hex.php