<?php
str bin2hex ( str $str )
where,
$str = The binary value as a STRING
to be converted to hexadecimal
?>
<?php
$bin01 = 'G�.p��8_��';
$bin2hex01 = bin2hex($bin01);
echo $bin2hex01;
?>
<?php
$bin02 = '101011010111000';
$bin2hex02 = bin2hex($bin02);
echo $bin2hex02;
?>
<?php
$bin03 = 'Easy come, easy go.';
$bin2hex03 = bin2hex($bin03);
echo $bin2hex03;
?>
<?php
echo "Testing bin2hex() : basic functionality.<br>";
// array with different values for $string
$strings = array (
//double quoted strings
/*1*/ "Here is a simple string",
"\t This String contains \t\t
some control characters\r\n",
"\x90\x91\x00\x93\x94\x90\x91\x95\x96\x97
\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f",
//single quoted strings
/*4*/ 'Here is a simple string',
'\t This String contains \t\t
some control characters\r\n',
'\x90\x91\x00\x93\x94\x90\x91\x95\x96\x97
\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f',
);
// loop through with each element of
// the $strings array to test bin2hex() function
$count = 1;
foreach($strings as $string) {
echo "<br><br>Iteration: $count<br>";
var_dump(bin2hex($string));
$count ++;
}
?>
<?php
$s = '';
for($i=0; $i<256; $i++) {
$s .= chr($i);
}
echo bin2hex($s)."<br><br>";
echo bin2hex("abc")."<br><br>";
?>