Delphi programmer needs help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
secs
Forum Newbie
Posts: 2
Joined: Sat Jun 07, 2008 4:19 am

Delphi programmer needs help

Post 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:
dbemowsk
Forum Commoner
Posts: 82
Joined: Wed May 14, 2008 10:30 pm

Re: Delphi programmer needs help

Post by dbemowsk »

Use while (strlen($str) < 100) <---notice the parenthases.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Delphi programmer needs help

Post 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.
secs
Forum Newbie
Posts: 2
Joined: Sat Jun 07, 2008 4:19 am

Re: Delphi programmer needs help

Post by secs »

Works great. Thanks heaps. Really appreciate it
Post Reply