code to reverse a bin2hex() function

function hex2bin($data) {
    $len = strlen($data);
    for($i=0;$i<$len;$i+=2) {
    	$newdata .= pack("C",hexdec(substr($data,$i,2)));
    }
   return $newdata;
}

just pass it the hex string and it will return the decoded data:

$coded="68656c6c6f";
$decoded=hex2bin($coded);

About Andy

This is my personal website where I (occasionally) post about things going on in the world of me. I am the creator of CommentLuv and administrator of comluv.com
Code , , , , , ,

0 responses to code to reverse a bin2hex() function


  1. John Doe

    Thanks! Works well.