note 113472 added to function.hex2bin
| From: | walf | Date: | Wed, 16 Oct 2013 04:41:37 +0000 |
| Subject: | note 113472 added to function.hex2bin | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-196561@lists.php.net to get a copy of this message | ||
A drop-in hex2bin emulator which behaves just like the the one in v5.5.1.
<?php
if (!function_exists('hex2bin')) {
function hex2bin($data) {
static $old;
if ($old === null) {
$old = version_compare(PHP_VERSION, '5.2', '<');
}
$isobj = false;
if (is_scalar($data) || (($isobj = is_object($data)) && method_exists($data,
'__toString'))) {
if ($isobj && $old) {
ob_start();
echo $data;
$data = ob_get_clean();
}
else {
$data = (string) $data;
}
}
else {
trigger_error(__FUNCTION__.'() expects parameter 1 to be string, ' . gettype($data) .
' given', E_USER_WARNING);
return;//null in this case
}
$len = strlen($data);
if ($len % 2) {
trigger_error(__FUNCTION__.'(): Hexadecimal input string must have an even length',
E_USER_WARNING);
return false;
}
if (strspn($data, '0123456789abcdefABCDEF') != $len) {
trigger_error(__FUNCTION__.'(): Input string must be hexadecimal string',
E_USER_WARNING);
return false;
}
return pack('H*', $data);
}
}
?>
----
Server IP: 69.147.83.199
Probable Submitter: 219.90.235.20
----
Manual Page -- http://php.net/manual/en/function.hex2bin.php
Edit -- https://master.php.net/note/edit/113472
Del: integrated -- https://master.php.net/note/delete/113472/integrated
Del: useless -- https://master.php.net/note/delete/113472/useless
Del: bad code -- https://master.php.net/note/delete/113472/bad+code
Del: spam -- https://master.php.net/note/delete/113472/spam
Del: non-english -- https://master.php.net/note/delete/113472/non-english
Del: in docs -- https://master.php.net/note/delete/113472/in+docs
Del: other reasons-- https://master.php.net/note/delete/113472
Reject -- https://master.php.net/note/reject/113472
Search -- https://master.php.net/manage/user-notes.php