What is the PHP equivalent of MySQL UNHEX ()?

What is the PHP equivalent of MySQL UNHEX ()?

For example, the following query and the PHP function must provide the same value.

SELECT UNHEX(c1) AS unhexed_c1 FROM table; $unhexed_c1=PHPs_UNHEX_Equivalent($c1); 
+6
source share
4 answers

There is a built-in hex2bin function if you use PHP> = 5.4.

+11
source

This can be done using pack :

 $unhexed = pack('H*', $hexstring); 
+8
source

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; } 
+5
source

I think you are looking for hex2bin

+2
source

Source: https://habr.com/ru/post/954851/


All Articles