Salesforce ID

Convert a 15 character case-sensitive Salesforce ID into an 18-character case-insensitive.

Normalise a salesforce ID

Submit a 15 character salesforce ID.

Salesforcce ID: 

/**
 * Convert 15 char id to 18 char id
 * @param String $id
 * @return Array $result
 */
public static function normaliseSforceID($id)
{
        $result = array();
        $length = strlen($id);
        /* Check for validity of SF Id AFAIK must it be alphanumerical and for converting we need it to be 15 characters long */
        if(!ctype_alnum($id))
        {
                $result[0] = false;
                $result[1] = 'Not a valid Salesforce Id:. $id . '!';
                return $result;
        }
        else
        {
                if($length == 18)
                {
                        $result[0] = true;
                        $result[1] =$id;
                        return $result;
                }
                if($length != 15)
                {
                        $result[0] = false;
                        $result[1] = 'Not a valid Salesforce Id . $id . ' length must be 15 of 18! It is: .  $length;
                        return $result;
                }
        }
        $suffix = '';
        for ($i = 0; $i < 3; $i++)
        {
                $flags = 0;
                for ($j = 0; $j < 5; $j++)
                {
                        $c = substr($id, ($i * 5 + $j), 1);
                        if (ord($c) >= ord('A') && ord($c) <= ord('Z'))
                        {
                                $flags += 1 << $j;
                        }
                }
                if ($flags <= 25)
                {
                        $suffix .= substr('ABCDEFGHIJKLMNOPQRSTUVWXYZ', $flags, 1);
                }
                else
                {
                        $suffix .= substr('012345', ($flags-26), 1);
                }
        }
        $result[0] = true;
        $result[1] =$id . $suffix;
        return $result;
}