I Spy Code - PHP

Convert string to hexadecimal values

Question:

How do you converts a string of ASCII characters to hexadecimal values using PHP?

Answer:

Use the PHP bin2hex() function.

Here is a PHP example that converts "Hello World" to hexadecimal values:

Source: (example.php)

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

Output:

$ php example.php
48656c6c6f20576f726c64

References:

http://www.w3schools.com/php/func_string_bin2hex.asp