chandru
chandru

Reputation: 11

generate 10 digits alphanumeric value in php with first,third,fourth digit must be alphabet

I need php code to generate 10 digits alphanumeric value with first,third and fourth digit must be Capital alphabet and alphabet 'o' or 'O' should not be in generated code.

Upvotes: 1

Views: 974

Answers (1)

Mark Baker
Mark Baker

Reputation: 212452

The following should provide you with the building blocks:

$letters = array_merge(range('A','N'),range('P','Z'));

$myRandom = $letters[(rand(1,count($letters))-1)];
$myRandom .= rand(0,9);
for($i = 3; $i <= 4; $i++) {
 $myRandom .= $letters[(rand(1,count($letters))-1)];
}
for($i = 5; $i <= 10; $i++) {
 $myRandom .= rand(0,9);
}

echo $myRandom;

Upvotes: 2

Related Questions