javascript - Rewrite php code to js -


help me, please, rewrite on javascript. fact when using third-party functions, return another.

$from = ''; $to = ''; $width = 16; if ($from === '') {     ($i = 0; $i <= 0xff; $i++) {         $from .= chr($i);         $to .= ($i >= 0x20 && $i <= 0x7e) ? chr($i) : ".";     } } $hex = str_split(bin2hex($data), $width * 2); $chars = str_split(strtr($data, $from, $to), $width); $offset = 0; $str = ""; foreach ($hex $i => $line) {     $str .= sprintf('%6x', $offset) . implode(' ', str_split($line, 2)) . ' ' . $chars[$i] . php_eol;     $offset += $width; } 

var = ''; var = ''; var width = '';  if (from === '') {     (var = 0; <= 0xff; i++) {         += string.fromcharcode(i);         += (i >= 0x20 && <= 0x7e) ? string.fromcharcode(i) : '.';     } }  var hex = []; var chars = [];  var datahex = parseint(_data, 2).tostring(16)  //split datahex 'width * 2' sized chunks (var = 0; < datahex.length; += width * 2) {     hex.push(datahex.split(i, + width*2)); }  var charsdata = _data;  //translate characters (var = 0; < charsdata.length; i++) {     if (from.indexof(charsdata[i]) > -1) {         charsdata[i] = to[from.indedof(charsdata[i])];     } }  //split charsdata 'width' sized chunks (var = 0, < charsdata.length; += width) {     chars.push(charsdata.split(i, width)); }  var offset = 0; var str = '';  (var = 0; < hex.length; i++) {     var line = hex[i];      /*string formatting code goes here*/      offset += width;  } 

this should started.

_data php's $data, whatever may be.

the code untested , didn't have enough time finish last loop. you'll have figure out string formatting part out or if still need , no 1 else has answered tomorrow, i'll test , finish :)


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -