note 96119 added to ref.strings

From: Date: Tue, 09 Feb 2010 19:12:41 +0000
Subject: note 96119 added to ref.strings
Groups: php.notes 
Request: Send a blank email to php-notes+get-165804@lists.php.net to get a copy of this message
@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); } ---- Server IP: 69.147.83.197 Probable Submitter: 212.240.194.66 ---- Manual Page -- http://www.php.net/manual/en/ref.strings.php Edit -- https://master.php.net/note/edit/96119 Del: integrated -- https://master.php.net/note/delete/96119/integrated Del: useless -- https://master.php.net/note/delete/96119/useless Del: bad code -- https://master.php.net/note/delete/96119/bad+code Del: spam -- https://master.php.net/note/delete/96119/spam Del: non-english -- https://master.php.net/note/delete/96119/non-english Del: in docs -- https://master.php.net/note/delete/96119/in+docs Del: other reasons-- https://master.php.net/note/delete/96119 Reject -- https://master.php.net/note/reject/96119 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#165804) next »