我在这个等式中遇到了问题,无法使它返回正确的值。根据Steam的说法,方程Steam_community_number = (Last_part_of_steam_id * 2) + 76561197960265728 + Second_to_last_part_of_steam_id
应该返回64位Steam社区ID。目前,该方程正在返回7.6561198012096E+16
。方程应该返回76561198012095632
,在某种程度上与它已经返回的内容几乎相同。我如何将返回的E+16值转换为正确的值,如上面在下面的代码中所述?谢谢
function convertSID($steamid) {
if ($steamid == null) { return false; }
//STEAM_X:Y:Z
//W=Z*2+V+Y
//Z, V, Y
//Steam_community_number = (Last_part_of_steam_id * 2) + 76561197960265728 + Second_to_last_part_of_steam_id
if (strpos($steamid, ":1:")) {
$Y = 1;
} else {
$Y = 0;
}
$Z = substr($steamid, 10);
$Z = (int)$Z;
echo "Z: " . $Z . "</br>";
$cid = ($Z * 2) + 76561197960265728 + $Y;
echo "Equation: (" . $Z . " * 2) + 76561197960265728 + " . $Y . "<br/>";
return (string)$cid;
}
我用$cid = convertSID("STEAM_0:0:25914952");
调用这个函数
如果您想查看输出的示例,请查看此处:http://joshua-ferrara.com/hkggateway/sidtester.php
更改
return (string)$cid;
至
return number_format($cid,0,'.','');
请注意,这将返回一个字符串,如果你对它进行任何计算,它将被转换回float。要对大整数进行数学运算,请使用bc_math
扩展名:http://www.php.net/manual/en/book.bc.php
编辑:您的函数转换为使用bcmath:
function convertSID($steamid) {
if ($steamid == null) { return false; }
//STEAM_X:Y:Z
//W=Z*2+V+Y
//Z, V, Y
//Steam_community_number = (Last_part_of_steam_id * 2) + 76561197960265728 + Second_to_last_part_of_steam_id
$steamidExploded = explode(':',$steamid);
$Y = (int)steamidExploded[1];
$Z = (int)steamidExploded[2];
echo "Z: " . $Z . "</br>";
$cid = bcadd('76561197960265728 ',$Z * 2 + $Y);
echo "Equation: (" . $Z . " * 2) + 76561197960265728 + " . $Y . "<br/>";
return $cid;
}