CKTIS / PHP
hex2bin()
Decode each pair of hexadecimal digits as one byte.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
hex2bin(string $string): string|falseDecode each pair of hexadecimal digits as one byte. Both letter cases are accepted. An odd length or a nonhexadecimal character emits E_WARNING and returns false. A valid empty string decodes to an empty string.
Signature
hex2bin(string $string): string|false
Example output
[["ab00",false,false,""],[true,true]]
Examples
<?php
$warnings = [];
set_error_handler(function($level) use (&$warnings) { $warnings[] = $level === E_WARNING; return true; });
$values = [bin2hex(hex2bin("aB00")),hex2bin("f"),hex2bin("xy"),hex2bin("")];
restore_error_handler(); echo json_encode([$values,$warnings]);
Result
[["ab00",false,false,""],[true,true]]