<?php
function oldTextual($steamid) {
$result = 'Invalid input.';
if (!preg_match('([a-zA-Z])', $steamid) && strlen($steamid) === 17) { // 64-bit int
$acc_id = bcsub($steamid, '76561197960265728');
$result = 'STEAM_0:';
if ($acc_id % 2 === 0)
$result .= '0:';
else
$result .= '1:';
$result .= bcdiv($acc_id, '2', 0);
}
if (substr($steamid, 0, 2) === "U:") { // New textual format
$split = explode(':', $steamid);
$result = 'STEAM_0:';
$z = (int)$split[2];
if ($z % 2 === 0)
$result .= '0:';
else
$result .= '1:';
$acc_id = bcdiv($z, '2', 0);
$result .= $acc_id;
}
return $result;
}
function newTextual($steamid) {
$result = 'Invalid input.';
if (substr($steamid, 0, 6) === 'STEAM_') { // Old textual format
$split = explode(':', $steamid);
$y = $split[1];
$z = $split[2];
$acc_id = bcadd(bcmul($z, '2'), $y);
$result = 'U:1:' . $acc_id;
}
if (!preg_match('([a-zA-Z])', $steamid) && strlen($steamid) === 17) { // 64-bit int
$acc_id = bcsub($steamid, '76561197960265728');
$result = 'U:1:' . $acc_id;
}
return $result;
}
function numeric($steamid) {
$result = 'Invalid input.';
if (substr($steamid, 0, 6) === 'STEAM_') { // Old textual format
$split = explode(':', $steamid);
$commid = bcmul($split[2], '2');
if ($split[1] === '1')
$commid = bcadd($commid, '1');
$result = bcadd($commid, '76561197960265728');
}
if (substr($steamid, 0, 2) === "U:") { // New textual format
$filter = str_replace(array('[', ']'), '', $steamid);
$split = explode(':', $filter);
$result = bcadd($split[2], '76561197960265728');
}
return $result;
}
$steamid64 = '76561198074715892';
$steamid32 = 'STEAM_0:0:57225082';
$steamid3 = 'U:1:114450164';
echo oldTextual($steamid64) . '<br>';
echo oldTextual($steamid3) . '<br>';
echo newTextual($steamid64) . '<br>';
echo newTextual($steamid32) . '<br>';
echo 'http://steamcommunity.com/profiles/' . numeric($steamid32) . '<br>';
echo 'http://steamcommunity.com/profiles/' . numeric($steamid3);
preferences:
43.1 ms | 402 KiB | 5 Q