Função bin2hex() PHP
Exemplo
Converter "Shanghai" para valor hexadecimal:
<?php $str = bin2hex("Shanghai"); echo($str); ?>
Definição e Uso
A função bin2hex() converte strings de caracteres ASCII em valores hexadecimais. A string pode ser convertida de volta usando a função pack().
Sintaxe
bin2hex(string)
Parâmetros | Descrição |
---|---|
string | Obrigatório. A string a ser convertida. |
Detalhes Técnicos
Retorno: | Retorna o valor hexadecimal da string a ser convertida. |
Versão PHP: | 4+ |
Mais Exemplos
Exemplo 1
Converter uma string de binário para hexadecimal e vice-versa:
<?php $str = "Shanghai"; echo bin2hex($str) . "<br>"; echo pack("H*",bin2hex($str)) . "<br>"; ?>