Latest web development tutorials

PHP hex2bin () function

PHP String Reference PHP String Reference

Examples

To convert a hexadecimal value to ASCII characters:

<?php
echo hex2bin("48656c6c6f20576f726c6421");
?>

Examples of the above output:

Hello World!


Definition and Usage

hex2bin () function to convert a string of hexadecimal values ​​to ASCII characters.


grammar

hex2bin( string )

参数 描述
string 必需。要转换的十六进制值。

technical details

return value: Returns the converted string of ASCII characters, and if that fails it returns FALSE.
PHP version: 5.4.0+
Update log: Since PHP 5.4.1 onwards, if the string length is odd, then throw a warning. In PHP 5.4.0, the odd string is silently accepted, but the last byte will be removed.

Since PHP 5.5.1 onwards, if the string is not a valid hexadecimal string, a warning is thrown.


PHP String Reference PHP String Reference