Jump to content

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;

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.