Page 1 of 1

Delphi programmer needs help

Posted: Sat Jun 07, 2008 4:25 am
by secs
Guys. I normally write Windows apps using Delphi. I use a program called PHPRunner to do a bit of web interfacing to a Mysql database that one of my applications uses.

When adding a record, I have phprunner fire an event before it posts a new record and in that I need to generate a text or string of 100 random charecters in length

I have looked around and came up with


$str = 'webadd';
while strlen($str) < 100
{
$str = $str . rand();

}


PHP runner creates a section that looks like


function BeforeAdd(&$values,&$message,$inline)
{

} // function BeforeAdd

and I have added my code between the {}

but it seems to fail. Would someone help me a bit please? :banghead:

Re: Delphi programmer needs help

Posted: Sat Jun 07, 2008 9:37 am
by dbemowsk
Use while (strlen($str) < 100) <---notice the parenthases.

Re: Delphi programmer needs help

Posted: Sat Jun 07, 2008 10:41 am
by Benjamin

Code: Select all

 
function random_string($len)
{
    $chars = array_merge(range('0', '9'),range('A', 'Z'), range('a', 'z'));
    $cnt = count($chars) - 1;
    $key = null;
    for ($i = 0; $i < $len; $i++) $key .= $chars[mt_rand(0, $cnt)];
    return $key;
}
 
$str = random_string(100);
 
Here is a function that will create a random string which includes numbers, uppercase and lowercase letters.

Re: Delphi programmer needs help

Posted: Sun Jun 08, 2008 1:35 am
by secs
Works great. Thanks heaps. Really appreciate it