Skip to content

Instantly share code, notes, and snippets.

@imvision
Forked from almirsarajcic/steamid_conversion.php
Last active December 22, 2015 16:19
Show Gist options
  • Save imvision/6498754 to your computer and use it in GitHub Desktop.
Save imvision/6498754 to your computer and use it in GitHub Desktop.
Function to convert 64-bit numbers to 32-bit and vice verse.
<?php
function convert_id($id)
{
if (strlen($id) === 17)
{
$converted = substr($id, 3) - 61197960265728;
}
else
{
$converted = '765'.($id + 61197960265728);
}
return (string) $converted;
}
$sixtyfour = '76561197992765754';
$thirtytwo = '32500026';
var_dump(convert_id($thirtytwo) === $sixtyfour); // bool(true)
var_dump(convert_id($sixtyfour) === $thirtytwo); // bool(true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment