Thursday, 25 September 2014

bin2hex in PHP

PHP bin2hex() function is utilized to changes over a string of binary characters to hexadecimal values. pack() function reverses it again.

Syntax:

bin2hex(string)
string : Required. The input string.

Example:

<?php
echo "<strong>Converting a string value from binary to hex and back :<strong><br />";
$str_name = "Good Morning!";
echo bin2hex( $str_name )."<br />";
echo pack("H*",bin2hex($str_name));
?>

Output will be:

Converting a string value from binary to hex and back :
476f6f64204d6f726e696e6721
Good Morning!

0 comments:

Post a Comment