Re: Strange Numeric Conversion...

From: Date: Fri, 02 Apr 2004 23:26:36 +0000
Subject: Re: Strange Numeric Conversion...
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-182213@lists.php.net to get a copy of this message
* Thus wrote Monty (monty3@hotmail.com): > I tried removing the zeros, but, I get the same result: > > $id = 000011; > $id = ltrim($id, '0'); > echo $id; // Displays: 9 instead of 11 ??? > > This didn't work either: > > $id = 000011; > settype($id, 'string'); > $id = ltrim($id, '0'); > echo $id; // Displays: 9 instead of 11 ??? This is expected, $id becomes 9 as soon as you assign it. the ltrim() function's dont see any 0. this will work however: $id = "0000011"; echo (int)$id; - or $id = "0000011"; echo ltrim($id, '0'); > No matter what I do, $id=000011 is seen as "9". Only way is to pass the > number without the zeros ($id=11), but, because this data is being read from > a database, I can't change the format because PHP seems to be converting it > immediately to a 9 instead of reading it as 11 or even 000011. This shouldn't be happening. A variable that contains a value of '000011' will not be seen as on octal value. > > If PHP sees this as an octal, then why does gettype(000011) = INTEGER? This > makes no sense. Thats because 000011 is an integer in octal notation. Curt -- "I used to think I was indecisive, but now I'm not so sure."

« previous php.general (#182213) next »