The following PHP code converts a Steam ID (STEAM_X:Y:Z) into a steam community ID. It has been sitting on my desktop for a while now, and I need to do something with it.
<?php
function steamID2CommunityID($steam_id) {
$steam_id = preg_replace("/^STEAM_/i", "", $steam_id);
if (preg_match("/^0:([0-1]):([0-9]+)$/", $steam_id, $m)) {
$community_id = $m[2];
$community_id = bcmul($community_id, 2);
$community_id = bcadd($community_id, "76561197960265728");
$community_id = bcadd($community_id, $m[1]);
return $community_id;
} else {
throw new Exception("Invalid Steam ID not of format 0:[0-1]:[0-9]+");
}
}
function steamID2CommunityID($steam_id) {
$steam_id = preg_replace("/^STEAM_/i", "", $steam_id);
if (preg_match("/^0:([0-1]):([0-9]+)$/", $steam_id, $m)) {
$community_id = $m[2];
$community_id = bcmul($community_id, 2);
$community_id = bcadd($community_id, "76561197960265728");
$community_id = bcadd($community_id, $m[1]);
return $community_id;
} else {
throw new Exception("Invalid Steam ID not of format 0:[0-1]:[0-9]+");
}
}
I'm on Twitter!