PHP hex2bin function



 The function of the PHP hex2bin function is to convert a hexadecimal string into a binary string, but it should be noted that in the concept of digital processing, the object processed by the PHP hex2bin function is a string rather than a numeric character. To convert hexadecimal digital characters into binary digital characters, you can use the base_convert function to process.


 with PHP hex2bin function corresponding to the function are: PHP BIN2HEX function .

PHP hex2bin function syntax
 string hex2bin ( string $data );
The PHP hex2bin function can only use one parameter at a time. This parameter is a general string, not a numeric string. Starting from PHP 5.5.1, when the string thrown into the hex2bin function is an invalid hexadecimal string, hex2bin The function will return an error message of E_WARNING level, which is a new feature. In PHP 5.4.0, if there are extra string characters, there will be no error message. The extra string characters will be truncated by the hex2bin function, and there will be exception messages until PHP 5.4.1.

PHP hex2bin function example
<?php
$newhex = hex2bin("57656c636f6d6520746f205769626962692e");
var_dump($newhex);
?>
Example output
string(18) "Welcome to Wibibi."
In the example, we prepared a hexadecimal string and converted it into a binary string through the hex2bin function, and stored it in the $newhex variable , and then used the var_dump function to output the conversion result, so that the original The complicated hexadecimal system string becomes the binary system sentence that can be read, this is the main function of PHP hex2bin function.

Post a Comment

0 Comments