Base de conhecimentoCentro de Exames
PT · PTPortuguês (Portugal)
Escolher idioma13

CKTIS / PHP

hex2bin()

Descodifica cada par hexadecimal como um byte sem distinguir maiúsculas.

Versão: PHP 8.4; repository runtime, production runtime not attested

Sintaxe

hex2bin(string $string): string|false

Descodifica cada par hexadecimal como um byte sem distinguir maiúsculas. Um comprimento ímpar ou um caráter inválido produz E_WARNING e false. Uma cadeia vazia válida permanece vazia.

Assinatura

hex2bin(string $string): string|false

Saída do exemplo

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

Exemplos

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

Fontes