Jump to content

random lettering question


chris_rulez001

Recommended Posts

You can use the rand() function and specify a minimum and a maximum making the range in the characters you want. If you want lower case letters, you can use:

 

for ($i=0;$i<18;$i++)
echo chr(rand(97, 122));

 

If you want more than just lower case letters, mess around with the min and max.

You can use the rand() function and specify a minimum and a maximum making the range in the characters you want. If you want lower case letters, you can use:

 

for ($i=0;$i<18;$i++)
echo chr(rand(97, 122));

 

If you want more than just lower case letters, mess around with the min and max.

 

thanks

Generate a random number in the ASCII translation area of your choice and apply it to the chr() function

http://us3.php.net/manual/en/function.chr.php

i.e

<?php
$codelength = 15;
$i = 1;
$string = "";
while($i<=$codelength){
$type = rand(1,3);
switch ($type){
//Number
case 1:
$string .= chr(rand(48,57));
break;
//Upper Case Letter
case 2:
$string .= chr(rand(65,90));
break;
//Lower Case Letter
default:
$string .= chr(rand(97,122));
}
$i++;
}
//$string is now a 15 character long random combo of numbers, uppercase, lowercase letters/numbers
echo $string;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.