Last active
October 26, 2016 12:16
-
-
Save dahse89/49bfd1bcd08b6c68d880d7e67e228b5c to your computer and use it in GitHub Desktop.
salesforce 15 digit to 18 digit id. Function to calculate the checksum.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function salesForceIdChecksum($id) | |
{ | |
$map = implode('',array_merge(range('A', 'Z'), range(0, 9))); | |
$checksum = ''; | |
foreach (str_split($id, 5) as $chunk) { | |
$checksum .= substr($map, bindec( strrev(array_reduce(str_split($chunk, 1),function($carry, $item){ | |
$carry .= (!is_numeric($item) && $item == strtoupper($item)) ? '1' : '0'; | |
return $carry; | |
},''))),1); | |
} | |
return $checksum; | |
} | |
// example | |
//$_15ID = '001b000000dA3YY'; | |
//$_18ID = $_15ID. salesForceIdChecksum($_15ID); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment