[Openupload-svn-update] SF.net SVN: openupload:[227] trunk/lib/general.inc.php
Status: Beta
Brought to you by:
tsdogs
|
From: <ts...@us...> - 2009-02-05 15:40:10
|
Revision: 227
http://openupload.svn.sourceforge.net/openupload/?rev=227&view=rev
Author: tsdogs
Date: 2009-02-05 15:40:07 +0000 (Thu, 05 Feb 2009)
Log Message:
-----------
add alphanumerical random string generation option
Modified Paths:
--------------
trunk/lib/general.inc.php
Modified: trunk/lib/general.inc.php
===================================================================
--- trunk/lib/general.inc.php 2009-02-03 18:48:50 UTC (rev 226)
+++ trunk/lib/general.inc.php 2009-02-05 15:40:07 UTC (rev 227)
@@ -51,10 +51,28 @@
exit(0);
}
-function randomName($min = 10, $max = 20) {
+/* generates a random string of length between min and max
+ * if alpha is true it will generate an alphanumeric string
+ */
+function randomName($min = 10, $max = 20, $alpha = false) {
$result = '';
- for ($i = 1; $i<rand($min,$max); $i++) {
- $result.= rand(0,9);
+ $rmax = rand($min,$max);
+ for ($i = 0; $i<$rmax; $i++) {
+ if ($alpha) {
+ $x = rand(0,58);
+ echo $x;
+ if ($x<25) {
+ $x = chr(ord('a') + $x);
+ } else if ($x < 35 ) {
+ $x = $x - 25;
+ } else {
+ $x = chr(ord('A') + ($x - 35));
+ }
+ echo '='.$x.'<br>';
+ $result .= $x;
+ } else {
+ $result.= rand(0,9);
+ }
}
return $result;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|