note 126543 added to function.hex2bin
| From: | nino at re-gister dot com | Date: | Thu, 28 Oct 2021 15:16:36 +0000 |
| Subject: | note 126543 added to function.hex2bin | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-217123@lists.php.net to get a copy of this message | ||
if you want to convert a hex encoded string to a binary string without any notices/errors regardless
of the input, use this function:
<?php
function hex2binary($str)
{
return ctype_xdigit(strlen($str) % 2 ? "" : $str) ? hex2bin($str) : false;
}
hex2binary(""); // false
hex2binary("a"); // false
hex2binary("ab"); // binary-string
?>
if the return type is string, you have your binary-string. otherwise (bool) false.
----
Server IP: 45.112.84.4
Probable Submitter: 45.112.85.242 (proxied: 14.187.105.186)
----
Manual Page -- https://php.net/manual/en/function.hex2bin.php
Edit -- https://main.php.net/note/edit/126543
Del: integrated -- https://main.php.net/note/delete/126543/integrated
Del: useless -- https://main.php.net/note/delete/126543/useless
Del: bad code -- https://main.php.net/note/delete/126543/bad+code
Del: spam -- https://main.php.net/note/delete/126543/spam
Del: non-english -- https://main.php.net/note/delete/126543/non-english
Del: in docs -- https://main.php.net/note/delete/126543/in+docs
Del: other reasons-- https://main.php.net/note/delete/126543
Reject -- https://main.php.net/note/reject/126543
Search -- https://main.php.net/manage/user-notes.php