3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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(['[', ']'], '', $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);
based on opfRg
Output for 5.4.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
STEAM_0:0:57225082<br>STEAM_0:0:57225082<br>U:1:114450164<br>U:1:114450164<br>http://steamcommunity.com/profiles/76561198074715892<br>http://steamcommunity.com/profiles/76561198074715892
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[', expecting ')' in /in/p9cEB on line 68
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[', expecting ')' in /in/p9cEB on line 68
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `')'' in /in/p9cEB on line 68
Process exited with code 255.