|
Posted by adlerweb on 08/04/06 09:21
kuukelekuu@gmail.com wrote:
> I need to convert ascii chars to hex chars.
>
> I searched the internet, found hex to ascii, but nowhere is there a
> ascii to hex method created by anyone.
>
> Can anyone help me with that?
>
> Chears
>
I created such a method some time ago - maybe it can help you...
function ascii2hex($ascii) {
$hex = '';
for ($i = 0; $i < strlen($ascii); $i++) {
$byte = strtoupper(dechex(ord($ascii{$i})));
$byte = str_repeat('0', 2 - strlen($byte)).$byte;
$hex.=$byte." ";
}
return $hex;
}
function hex2ascii($hex){
$ascii='';
$hex=str_replace(" ", "", $hex);
for($i=0; $i<strlen($hex); $i=$i+2) {
$ascii.=chr(hexdec(substr($hex, $i, 2)));
}
return($ascii);
}
adlerweb
Navigation:
[Reply to this message]
|