PHP bin2hex() Function

PHP chop() Function
PHP addslashes() Function

In this article, you will learn;

  • How to convert the ASCII characters to the Hexadecimal values.

The PHP bin2hex() method converts the ASCII characters into hexadecimal values. We can convert back the hexadecimal value to the ASCII character using the pack() function in PHP.

What is the BIN2HEX() syntax of the function in PHP?

stringThe String to convert to hexadecimal – Required
PHP bin2hex() method

Example of the BIN2HEX() function

Example 1. In this example, we simply pass the string to the bin2hex() function and then print the output.

$str = bin2hex("Hello World!");

Example 2. In this example, we convert the string to a hexadecimal value and then convert it back to the ASCII string or character.

$str = "Hello world!";
echo bin2hex($str) . "<br>";
echo pack("H*",bin2hex($str)) . "<br>";
PHP chop() Function
PHP addslashes() Function
en English
Scroll to Top