Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old November 22nd, 2005, 12:05 AM
Carramba
Guest
 
Posts: n/a
Default generating data problem

Hi!

I am working on script that ll generate some random data, ll need it later
on to fil db for testing.
but know to my problem, I have limited generation of data to different
char_sets depending on need, but
the generated data is mixing all char_sets and I dont se why , so actually
it's generates data on pwd condition, where all chat_set are allowed.
hope you can help!

<?php
function generateSign ( $var , $length ){

$charset_1 = "0123456789";
$charset_2 = "abcdfghjkmnopqrstvwxyz";
$charset_3 = "ABCDEFGHIJKLMNOPQRESTUVWXYZ";
$possible =""; //<-- I allways reset it to null (?)

if ( $var == 'num') {
$possible = $charset_1;
}

if ( $var = 'text'){
$possible = $charset_2;
$possible .= $charset_3;
}

if ( $var = 'pwd' ){
$possible = $charset_1;
$possible .= $charset_2;
$possible .= $charset_3;
}

if ( $var = null){
die('Use: text , num, pwd. In function');
}

$i = 0;
$password = "";
while ( $i < $length ) {
$sign = substr( $possible, rand( 0, strlen( $possible )-1 ), 1 );
if ( !strstr( $generatedData, $sign ) ) {
$generatedData .= $sign;
$i++;
}
}
return $generatedData;
}

$antal= 0;
while( $antal < 10 ){
$namn = strtolower( generateSign( 'text', '12' ) ); //<-- ll generate text
sting including numbers
$phone = generateSign('num', '8' );//<-- ll generate text sting including
char
$email = strtolower( generateSign('text' , '6' ) ); //<-- ll generate text
sting including numbers
$pwd = md5( generateSign('pwd', '4') );
echo $antal.' , '.$namn.' , '.$pwd.', '.$phone.' , '.$email.' <BR>';
$antal++;
}


?>

--


Thanx in advance
________________________






  #2  
Old November 22nd, 2005, 12:05 AM
Carramba
Guest
 
Posts: n/a
Default Re: generating data problem

oh sorry for even possting it.. hehe
didn't se misstyping.. = instead of ==
all works fine..
  #3  
Old November 22nd, 2005, 12:05 AM
Chung Leong
Guest
 
Posts: n/a
Default Re: generating data problem

Also see http://fi.php.net/str_shuffle/.

  #4  
Old November 22nd, 2005, 12:07 AM
Steve
Guest
 
Posts: n/a
Default Re: generating data problem

In article <op.sz6eydu4eel3e6@big>, nospam@note.com (Carramba) wrote:
[color=blue]
> *Subject:* Re: generating data problem
> *From:* Carramba <nospam@note.com>
> *Date:* Sun, 13 Nov 2005 12:16:51 +0100
>
> oh sorry for even possting it.. hehe
> didn't se misstyping.. = instead of ==
> all works fine..
>[/color]
You're not the first, you certainly won't be the last...


- Steve
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,414 network members.