How to write the PHP function JScriptcodefunctiondecode (C) {vardigi = 16; varadd = 10; varplus = 7; varcha = 36; v how to write the PHP function
JScript code
function decode(C) { var digi=16; var add= 10; var plus=7; var cha=36; var I = -1; var H = 0; var B = ""; var J = C.length; var G = C.charCodeAt(J - 1); C = C.substring(0, J - 1); J--; for (var E = 0; E < J; E++) { var D = parseInt(C.charAt(E), cha) - add; if (D >= add) { D = D - plus } B += (D).toString(cha); if (D > H) { I = E; H = D } } var A = parseInt(B.substring(0, I), digi); var F = parseInt(B.substring(I + 1), digi); var L = (A + F - parseInt(G)) / 2; var K = (F - L) / 100000; L /= 100000; return { lat: K, lng: L }}document.write(decode('HHDFJGZVVIHIJG').lat+','+decode('HHDFJGZVVIHIJG').lng);
Functions of this JS function... How can I use PHP to write .. Thank you for running the function: 39.09917, 117.22348
------ Solution --------------------
Literal translation
PHP code
print_r(decode('HHDFJGZVVIHIJG'));function decode($C) { $digi = 16; $add = 10; $plus = 7; $cha = 36; $I = -1; $H = 0; $B = ""; $J = strlen($C); $G = ord($C{$J - 1}); $C = substr($C, 0, -1); $J--; for ($E = 0; $E < $J; $E++) { $D = base_convert($C{$E}, $cha, 10) - $add; if ($D >= $add) { $D = $D - $plus; } $B .= base_convert($D, 10, $cha); if ($D > $H) { $I = $E; $H = $D; } } $A = base_convert(substr($B,0, $I), $digi, 10); $F = base_convert(substr($B, $I + 1), $digi, 10); $L = ($A + $F - $G) / 2; $K = ($F - $L) / 100000; $L /= 100000; return array( 'lat' => $K, 'lng' => $L);}