At 22:50 8/5/2001, Jeroen van Wolffelaar wrote the following:
--------------------------------------------------------------
>> >Implementing something that has NOT that limitation, is far less trivial.
>>
>> function str_rand($len = 8, $class = 'a-zA-Z1-9')
>> {
>> static $init = 1;
>> if(1 == $init){
>> mt_srand((double) microtime() * 1000000);
>> $init = 0;
>> }
>> $chars = array();
>> for($i = 0; $i < $len; $i++){
>> $chars[] = chr(mt_rand(0,255));
>> }
>> return implode('', preg_grep('|['.preg_quote($class).']|',$chars));
>> }
>>
>> Just a little bit different syntax for the second argument.
>> What's the big deal? :)
>
>Okay, but hey, you're a PHP-expert with probably many years of experience...
Faaaar from that. :)
>By the way, your function won't return strings of length $len... ;)
Oh, shit. Optimization instead of a function. :)
I've been sitting before the CRT for 30 hours...
>And you could say that preg_grep is quite a hack.
Well, it nicely fits the bill - if you use the second argument as
a character class, preg_quote/grep() lends itself. Or do you mean the
concatenation? That's just a matter of formatting. Take it out of the
preg_grep() call, and it'll look better.
>Anyway, this didn't convince me it's trivial... I'm sorry.
ok. :) seems like the only function that'll be missing from PHP
will be write_the_app(); :)))
But this is really a non-issue. I'm fine with or without str_rand(),
I was just trying to show that it's pretty easy to write one in PHP,
and so the function isn't really necessary. I know, there's nl2br()
which _is_ simple, but that's backed by the fact that in a web-oriented
language, _everybody_ would write their own nl2br(). This is not the
case with str_rand()...
And now help me down off that soap box. :)
[EMAIL PROTECTED]
-------------
And the eyes of them both were opened and they saw that their files
were world readable and writable, so they chmoded 600 their files.
- Book of Installation chapt 3 sec 7
--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]