Categories

Thousands of experts bid on your personal project at ScriptLance.com

Random string

generates a random string from an array of characters

<?php
// function to generate random strings
function RandomString($length=32)
{
$randstr=”;
srand((double)microtime()*1000000);
//our array add all letters and numbers if you wish
$chars = array ( ‘a’,'b’,'c’,'d’,'e’,'f’);
for ($rand = 0; $rand <= $length; $rand++)
{
$random = rand(0, count($chars) -1);
$randstr .= $chars[$random];
}
return $randstr;
}
?>

and call it like this

<?php
echo RandomString(8);
?>

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

You must be logged in to post a comment.