Re: $str[0] vs $str{0} was : generate random ascii string

From: Date: Sat, 01 Sep 2001 18:46:01 +0000
Subject: Re: $str[0] vs $str{0} was : generate random ascii string
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-65616@lists.php.net to get a copy of this message
Hi Philip, Yes, I have a choice of PHP3 or 4 and this script happened to be in PHP 3 so I just tweaked it. I didn't realize that one day $chars[mt_rand(0,$chars_len)] would "no longer work", but at least it is backwards compatible now. I've made a mental note of that for future reference. PHP 3 also barked at is_numeric() which I just changed to intval() I should really do better bounds checking. How about: $len=intval($len); if (!$len) $len=8; kind regards, bill Philip Olson wrote: > It appears the only change you made was : > > > $tmp .= $chars[mt_rand(0,$chars_len)]; > > >From : > > > > $tmp .= $chars{mt_rand(0,$chars_len)}; > > Which is strange. the [] use on strings has been depreciated in favor > of {} as of php4 but I don't know at what version {} came into being > exactly. What version of PHP are you running, php3? Or, does anyone know > much about this? > > Anyway, glad it works :) > > For informational purposes, this depreciation is stated here : > > http://www.php.net/manual/en/language.types.string.php > > And for those watching at home, am referring to : > > $string = 'abc'; > > print $string[0]; // depreciated (might not work one day, when?) > > vs. > > print $string{0}; > > Both print 'a' though. > > Regards, > Philip Olson

« previous php.general (#65616) next »