Created
June 14, 2017 18:13
-
-
Save Belphemur/93e8f90138f2bebbe86f3ce109e0fa85 to your computer and use it in GitHub Desktop.
Salesforce ID 15 chars to 18 chars converter PHP
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 to18char(string $inputId) { | |
$suffix = ''; | |
for ($i = 0; $i < 3; $i++) { | |
$flags = 0; | |
for ($j = 0; $j < 5; $j++) { | |
$start = $i * 5 + $j; | |
$end = ($i * 5 + $j + 1) - $start; | |
$c = substr($inputId, $start, $end); | |
if (ctype_upper($c) && $c >= 'A' && $c <= 'Z') { | |
$flags = $flags + (1 << $j); | |
} | |
} | |
if ($flags <= 25) { | |
$suffix .= substr('ABCDEFGHIJKLMNOPQRSTUVWXYZ',$flags,1); | |
}else{ | |
$suffix .= substr('012345', $flags - 26, 1); | |
} | |
} | |
return $inputId . $suffix; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment