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?

bin2hex(string)
ParameterDescription
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.

<?php
$str = bin2hex("Hello World!");
echo($str);
?>

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

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