CKTIS / PHP
hex2bin()
Decodifica cada par hexadecimal como un byte sin distinguir mayúsculas.
Versión: PHP 8.4; repository runtime, production runtime not attested
Sintaxis
hex2bin(string $string): string|falseDecodifica cada par hexadecimal como un byte sin distinguir mayúsculas. La longitud impar o un carácter no válido producen E_WARNING y false. Una cadena vacía válida sigue vacía.
Firma
hex2bin(string $string): string|false
Salida del ejemplo
[["ab00",false,false,""],[true,true]]
Ejemplos
<?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]);
Resultado
[["ab00",false,false,""],[true,true]]