What is the PHP equivalent of MySQL's UNHEX()?
For instance, the following query and PHP function should provide the same value.
SELECT UNHEX(c1) AS unhexed_c1 FROM table;
$unhexed_c1=PHPs_UNHEX_Equivalent($c1);
There's a built-in function called hex2bin if you're running PHP >= 5.4.
It can be done with pack
:
$unhexed = pack('H*', $hexstring);
See How to convert hex to string or text in php:
function unhex($hex) {
for($i=0;$i<strlen($hex);$i+=2)
$str .= chr(hexdec(substr($hex,$i,2)));
return $str;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With