Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Salesforce ID 15 chars to 18 chars converter PHP
<?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