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);
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);
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;
}