首页 > 后端开发 > php教程 > 如何写成PHP函数

如何写成PHP函数

WBOY
发布: 2016-06-13 13:28:45
原创
1010 人浏览过

怎么写成PHP函数

JScript code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->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 = 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);

登录后复制

这个JS函数的功能。。。怎么用PHP写呀。。谢谢了,这个函数运行结果:39.09917,117.22348

------解决方案--------------------
直译即可
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 = $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);
} <div class="clear">
                 
              
              
        
            </div>
登录后复制
相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板