note 96119 deleted from ref.strings by danbrown

From: Date: Tue, 09 Feb 2010 19:13:30 +0000
Subject: note 96119 deleted from ref.strings by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-165805@lists.php.net to get a copy of this message
Note Submitter: NOSPAM at NOSPAM dot chemica dot co dot uk ---- @kriskra The 'best random string' generator gave me errors - one uninitialised string and an odd one where rand returned an index out of range of the string. This function is more verbose but does not use rand and defers looping to the str_shuffle function. A loop is only initiated if the length of the required string exceeds $c. function random_string($length = 10) { $c = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxwz0123456789"; while (strlen($c) < $length) { $c .= $c; } $c = str_shuffle($c); return substr($c, 0, $length); }

« previous php.notes (#165805) next »