Forum Moderators: coopster

Message Too Old, No Replies

PHP script for generating sample data

         

nuwanda

8:19 am on Jan 12, 2008 (gmt 0)

10+ Year Member



Anyone know of a script for generating data for sample mysql tables? You know, names, numbers, dates, etc.

Would save a lot of inputting :-)

Thanks.

eelixduppy

10:59 pm on Jan 13, 2008 (gmt 0)



I don't know exactly what you are talking about but it sounds like something that can be easily implemented yourself. Maybe you care to elaborate on what you are trying to accomplish?

PHP_Chimp

11:07 pm on Jan 13, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




function random_string ($length) {
$string = '';
for ($i=0;$i<$length;$i++) {
$case = mt_rand(1,2); // so you should get about 50% upper case, 50% lower case
switch ($case) {
case 1:
$string.= chr(mt_rand(65, 90)); // upper case
break;
case 2:
$string.= chr(mt_rand(97, 122)); // lower case
break;
}
}
return $string;
}

If you want punctuation or numbers then increase the max mt_rand in $case and add another case to the switch statement.