python代码转换 php,将一个简单的Python2代码转换为PHP

因为魔兽世界的服务器在我午休时间宕机了:// net, cid, lac = 25002, 9164, 4000

$net = 25002;

$cid = 9164;

$lac = 4000;

// import urllib

//a = '000E00000000000000000000000000001B0000000000000000000000030000'

$a = '000E00000000000000000000000000001B0000000000000000000000030000';

//b = hex(cid)[2:].zfill(8) + hex(lac)[2:].zfill(8)

$b = sprintf("%08x%08x", $cid, $lac);

//c = hex(divmod(net,100)[1])[2:].zfill(8) + hex(divmod(net,100)[0])[2:].zfill(8)

$c = sprintf("%08x%08x", $net % 100, floor($net / 100));

//string = (a + b + c + 'FFFFFFFF00000000').decode('hex')

$string = $a . $b . $c . 'FFFFFFFF00000000';

$newstring = '';

for( $i = 0, $count = strlen($string); $i < $count; $i++ ) {

$newstring .= sprintf("%c", hexdec($string{$i} . $string{++$i}));

}

//data = urllib.urlopen('http://www.google.com/glm/mmap',string)

$ch = curl_init('http://www.google.com/glm/mmap');

curl_setopt($ch, CURLOPT_POST, true);

curl_setopt($ch, CURLOPT_POSTFIELDS, $newstring);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

//r = data.read().encode('hex')

$r = curl_exec($ch);

//print float(int(r[14:22],16))/1000000, float(int(r[22:30],16))/1000000

$r = array_pop(unpack("H*", $r));

printf("%f, %f", hexdec(substr($r, 14, 8)) / 1000000, hexdec(substr($r, 22, 8)) / 1000000);

不过,我希望看到更优雅的十六进制转换。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值