개발/PHP

[PHP] hex2bin , bin2hex

지산동고라니 2020. 3. 16. 22:20

기본꼴

hex2bin ( string $data ) : string

bin2hex ( string $data ) : string

 

hex2bin함수는 16진법의 수를 ASCII 대응하여 string으로 바꾸어줌

bin2hex함수는 $data를 ASCII에 대응하여 16진법으로 바꾸어줌 

 

두 함수 모두 ASCII를 사용하기 때문에 영어 이외의 문자는 사용 불가

 

만약 다른 문자를 사용하고 싶으면 UTF8decode() , UTF8encode() 함수를 사용

 

https://www.php.net/manual/en/function.bin2hex.php

 

PHP: bin2hex - Manual

Here's a function to check if a string contains any 7-bit GSM characters. It might come useful for people working on SMS platforms.

https://www.php.net/manual/en/function.hex2bin.php

 

PHP: hex2bin - Manual

If you want to convert hex to GUID format (In my case, it was to convert GUID from MSSQL database) :