Your Ad Here
String Function
Execute String Function Online
String Functions Online Tool

Php String to Hex Tutorial

 

dechex() - String to Hex Tutorial

The php string function dechex() converts an int into a string.

string dechex ( int $number )

In order to convert a string into its hex representation, you need the following function. There are no php functions designed to convert a string to hex.

function strhex($str)
{
$hex = '';
for ($i=0; $i < strlen($str); $i++)
{
$hex .= dechex(ord($str[$i]));
}
return $hex;
}

The $str parameter is a string.
It returns a hex value which is the hexadecimal representation of the string.

 

Php String to Hex Example

Example: We have the string "HeLLo WoRlD!"
The php string-to-hex function returns the value 48654c4c6f20576f526c4421. This is a series of hex value each of which represent the hex representation of "HeLLo WoRlD!"

Test it online using our String-to-Hex Tool