Skip to content

Instantly share code, notes, and snippets.

@almirsarajcic
Last active October 20, 2020 22:06
Show Gist options
  • Star 23 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save almirsarajcic/4664387 to your computer and use it in GitHub Desktop.
Save almirsarajcic/4664387 to your computer and use it in GitHub Desktop.
Functions used to convert 64bit Steam ID to 32bit and the other way around.
<?php
function convert_steamid_64bit_to_32bit($id)
{
$result = substr($id, 3) - 61197960265728;
return (string) $result;
}
function convert_steamid_32bit_to_64bit($id)
{
$result = '765'.($id + 61197960265728);
return (string) $result;
}
$sixtyfour = '76561197992765754';
$thirtytwo = '32500026';
var_dump(convert_steamid_32bit_to_64bit($thirtytwo) === $sixtyfour); // bool(true)
var_dump(convert_steamid_64bit_to_32bit($sixtyfour) === $thirtytwo); // bool(true)
@progressivewebdev
Copy link

Thanks! you saved much time for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment