jfur7
jfur7

Reputation: 77

How to add A through Z at the end of a string PHP

What I am doing is taking a vehicle VIN number and taking the last 6 digits of it and storing it as a stock number. The issue I have is I have a function that goes and checks the database to make sure that stock number exists. If it does (can have the same vehicle in inventory again from buy back, etc) I want to concat at the end of the sting A through Z.

if(strlen($vin) > 9) {
    $stocknum = substr($vin,-6);
    while(verfiyUnique($mysqli, $stocknum) != true) {
        if(strlen($stocknum < 7)) {
            $stocknum = substr($vin,-6) . "A";
        }else{
            ?
        }
    }
    return $stocknum;

How do I increment lets say A to B or B to C if it does match?

Thanks in advance for your help!

Upvotes: 0

Views: 49

Answers (2)

scottlimmer
scottlimmer

Reputation: 2278

You could also use $letters = range('A','Z') to create an array of uppercase letters and then increment an index variable to access the array. E.g.: $letters[$i] would output A

Upvotes: 1

scottlimmer
scottlimmer

Reputation: 2278

You could increment the ascii number and use the chr() function to convert it to the relevant character. E.g.: chr(65) would output A

See http://php.net/manual/en/function.chr.php for more info as well as a link to an ASCII table.

Upvotes: 1

Related Questions