Why we use bin2hex() Function in PHP

By Prof. Fazal Rehman Shamil

Why we use bin2hex() Function in PHP

The bin2hex() function is used to converts a string to hexadecimal. This conversion is performed byte-wise and with the high-nibble first.

Note: It is not for converting strings representing binary digits into hexadecimal.



What are the Parameters?

The bin2hex($my_string) function accepts a single parameter $my_string. This is the string that will be converted to hexadecimal values.

What are Return Values?

The bin2hex($my_string) function returns the hexadecimal value of the string passed in the parameter.


Input : string = ” t4tutorials”

Output : 74347475746f7269616c73

Input : string = ” 444″

Output : 343434

Let’s see some PHP programs that illustrate the bin2hex() function.

Example 1: PHP bin2hex() function



Example 2: PHP bin2hex() function



Prof.Fazal Rehman Shamil (Available for Professional Discussions)
1. Message on Facebook page for discussions,
2. Video lectures on Youtube
3. Email is only for Advertisement/business enquiries.