Monday, July 14, 2008

Random characters

We are going to build a function that returns a character between some that we set initially. The comments to the function are blue-colored:
// Start of function
function gencod()
{

// Wa set a list of 35 characters and we put it in a string named $characters
$characters="1234567890abcdefghijklmnopqrstuvwxyz";

// The function rand takes a character between those defined before and assign it to $chargen
$chargen=$characters{rand(0,35)};

// The function return the character
return $chargen;
}
// End of function

Article written by the webmaster of Tuttophp

No comments: