hexDecode.php
Table of Contents
Functions
- hexDecode() : string|false
- Decodes a hexadecimal string into raw bytes.
Functions
hexDecode()
Decodes a hexadecimal string into raw bytes.
hexDecode(string $value) : string|false
Strict, warning-free counterpart of hex2bin() :
- Accepts both lowercase and uppercase digits (
[0-9a-fA-F]). - Requires an even number of characters ; an odd length yields
false. - Rejects any character outside the hex alphabet (including whitespace and
non-ASCII bytes) with
falseinstead of PHP's native warning. - The empty string decodes to the empty string.
The function does not raise exceptions ; it returns false on any invalid
input, mirroring the contract of base64UrlDecode().
Note: when comparing a decoded value to a known secret (e.g. an HMAC tag), always use hash_equals() for constant-time comparison.
Parameters
- $value : string
-
The hexadecimal string to decode. May be empty.
Tags
Return values
string|false —The decoded raw bytes, or false if $value is not a
valid hexadecimal string of even length.