yep
[handydandy.git] / hex.php
blob9cae35c9070e05e4036c41e4fa24968daa293601
1 <?php
2 function tohex($data){
3 $ret = array();
4 $offset = 0;
5 $len = strlen($data);
7 $ascii = '';
8 $hex = array();
9 for ($i = $j = 0; $i < $len; $i++){
10 $hex[] = sprintf("%02x", ord($data[$i]));
12 if ((ord($data[$i]) >= ord(' ') && ord($data[$i]) <= ord('~')) || (ord($data[$i]) >= 0xa0 && ord($data[$i]) <= 0xa7)){
13 $ascii .= utf8_encode(htmlentities($data[$i]));
14 } else {
15 $ascii .= '.';
18 if ($j == 7) $ascii .= ' ';
20 if (++$j == 16 || $i == $len - 1){
21 $ret[] = array(sprintf("%04x",$offset),$hex,$ascii);
23 $ascii = '';
24 $hex = array();
26 $offset += 16;
27 $j = 0;
30 return $ret;