Re: Strange Numeric Conversion...
| From: | Red Wingate | Date: | Fri, 02 Apr 2004 21:59:35 +0000 |
| Subject: | Re: Strange Numeric Conversion... | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-182203@lists.php.net to get a copy of this message | ||
trim will not work, try something like:
$id = preg_replace("/^0+(.*)$/","//1",$id);
instead
Monty wrote:
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 ???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. If PHP sees this as an octal, then why does gettype(000011) = INTEGER? This makes no sense. Monty.From: jay.blanchard@niicommunications.com (Jay Blanchard) Newsgroups: php.general Date: Fri, 2 Apr 2004 15:38:03 -0600 To: "Monty" <monty3@hotmail.com>, <php-general@lists.php.net> Subject: RE: [PHP] Strange Numeric Conversion... [snip] Why is this happening??? $id = 000011;echo $id; // Displays: 9$id = 11;echo $id; // Displays: 11How do I make the first number (00011) display as 11? Why is it showing 9? [/snip] First of all you have "naked" numbers. The first one, 000011, looks like a binary number (which actually should be 3). You are going to have to trim the leading zero's from the number to have it display as 11.