Base di conoscenzaCentro esami
ITItaliano
Scegli la lingua13

CKTIS / PHP

hex2bin()

Decodifica ogni coppia esadecimale come un byte senza distinguere maiuscole.

Versione: PHP 8.4; repository runtime, production runtime not attested

Sintassi

hex2bin(string $string): string|false

Decodifica ogni coppia esadecimale come un byte senza distinguere maiuscole. Una lunghezza dispari o un carattere non valido producono E_WARNING e false. Una stringa vuota valida resta vuota.

Firma

hex2bin(string $string): string|false

Output dell’esempio

[["ab00",false,false,""],[true,true]]

Esempi

<?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]);

Risultato

[["ab00",false,false,""],[true,true]]

Fonti