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: [EMAIL PROTECTED] (Jay Blanchard)
Newsgroups: php.general
Date: Fri, 2 Apr 2004 15:38:03 -0600
To: "Monty" <[EMAIL PROTECTED]>, <[EMAIL PROTECTED]>
Subject: RE: [PHP] Strange Numeric Conversion...

[snip]
Why is this happening???

$id = 000011;
echo $id;       // Displays: 9

$id = 11;
echo $id;       // Displays: 11

How 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.



-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to