Re: [PHP] Strange Numeric Conversion...

2004-04-05 Thread John Nichel
Jay Blanchard wrote:
[snip]
"naked"
[/snip]
Dang John, I guess I don't think octally any more!
John writes out his grocery list in Hex.  ;)

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


Re: [PHP] Strange Numeric Conversion...

2004-04-02 Thread John Holmes
Monty wrote:

Thanks Red, but, still the same problem:

$id = 11;
$id2 = preg_replace("/^0+(.*)$/","\\1",$id);
echo $id2;  // Displays 9
echo $id;   // Displays 9 as well.
If the number begins with a zero, there seems to be no way to tell PHP this
is an integer, not an octal. The conversion happens as soon as the number is
stored in the variable, it appears, which is why everything done afterwards
makes no difference, because $id=11; seems to be stored as $id=>9 by
PHP. 
011 and 9 are the exact same number, but represented in different bases! 
Maybe this is the concept you're not grasping. When you say $id = 
11, then you're telling PHP to assign the value of 9 to $id, plain 
and simple.

Can we take a step back here and ask where you're getting "11" from?

---John Holmes...

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


Re: [PHP] Strange Numeric Conversion...

2004-04-02 Thread John Holmes
Red Wingate wrote:

ever tryed telling PHP to display the variable as an integer?

echo (integer) $id ;
Ever "tryed" realizing 0x09, 011, and 9 are all integers (just different 
bases)?

;)

---John Holmes...

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


Re: [PHP] Strange Numeric Conversion...

2004-04-02 Thread Curt Zirzow
* Thus wrote Monty ([EMAIL PROTECTED]):
> I tried removing the zeros, but, I get the same result:
> 
> $id = 11;
> $id = ltrim($id, '0');
> echo $id;   // Displays: 9 instead of 11 ???
> 
> This didn't work either:
> 
> $id = 11;
> 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 = "011";
  echo (int)$id;

  - or

  $id = "011";
  echo ltrim($id, '0');

> No matter what I do, $id=11 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 11.

  This shouldn't be happening. A variable that contains a value of
  '11' will not be seen as on octal value.

> 
> If PHP sees this as an octal, then why does gettype(11) = INTEGER? This
> makes no sense.

 Thats because 11 is an integer in octal notation.

Curt
-- 
"I used to think I was indecisive, but now I'm not so sure."

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



Re: [PHP] Strange Numeric Conversion...

2004-04-02 Thread Curt Zirzow
* Thus wrote Daniel Clark ([EMAIL PROTECTED]):
> Found this:
> 
> $a = 1234; # decimal number
> $a = -123; # a negative number
> $a = 0123; # octal number (equivalent to 83 decimal)
> $a = 0x1A; # hexadecimal number (equivalent to 26 decimal)

$a is integer in all these cases, the only difference is the last 
two are set using different base notation.


Curt
-- 
"I used to think I was indecisive, but now I'm not so sure."

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



Re: [PHP] Strange Numeric Conversion...

2004-04-02 Thread Daniel Clark
Found this:

$a = 1234; # decimal number
$a = -123; # a negative number
$a = 0123; # octal number (equivalent to 83 decimal)
$a = 0x1A; # hexadecimal number (equivalent to 26 decimal)

http://www.phpbuilder.com/manual/language.types.integer.php#language.types.integer.casting


> hm
>
> ever tryed telling PHP to display the variable as an integer?
>
> echo (integer) $id ;

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



Re: [PHP] Strange Numeric Conversion...

2004-04-02 Thread Red Wingate
hm

ever tryed telling PHP to display the variable as an integer?

echo (integer) $id ;

 -- red

Daniel Clark wrote:

Doesn't putting and x11 tell PHP it's a decimal format?


   $id = 11;
   $id2 = preg_replace("/^0+(.*)$/","\\1",$id);
   echo $id2;  // Displays 9
   echo $id;   // Displays 9 as well.
If the number begins with a zero, there seems to be no way to tell PHP
this
is an integer, not an octal. The conversion happens as soon as the number
is
stored in the variable, it appears, which is why everything done
afterwards
makes no difference, because $id=11; seems to be stored as $id=>9 by
PHP.


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


Re: [PHP] Strange Numeric Conversion...

2004-04-02 Thread Daniel Clark
Doesn't putting and x11 tell PHP it's a decimal format?

> $id = 11;
> $id2 = preg_replace("/^0+(.*)$/","\\1",$id);
>
> echo $id2;  // Displays 9
> echo $id;   // Displays 9 as well.
>
> If the number begins with a zero, there seems to be no way to tell PHP
> this
> is an integer, not an octal. The conversion happens as soon as the number
> is
> stored in the variable, it appears, which is why everything done
> afterwards
> makes no difference, because $id=11; seems to be stored as $id=>9 by
> PHP.

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



Re: [PHP] Strange Numeric Conversion...

2004-04-02 Thread Monty
Thanks Red, but, still the same problem:

$id = 11;
$id2 = preg_replace("/^0+(.*)$/","\\1",$id);

echo $id2;  // Displays 9
echo $id;   // Displays 9 as well.

If the number begins with a zero, there seems to be no way to tell PHP this
is an integer, not an octal. The conversion happens as soon as the number is
stored in the variable, it appears, which is why everything done afterwards
makes no difference, because $id=11; seems to be stored as $id=>9 by
PHP. 


> From: [EMAIL PROTECTED] (Red Wingate)
> Organization: ErisX Development
> Reply-To: [EMAIL PROTECTED]
> Newsgroups: php.general
> Date: Sat, 03 Apr 2004 00:01:43 +0200
> To: [EMAIL PROTECTED]
> Cc: Monty <[EMAIL PROTECTED]>,  [EMAIL PROTECTED]
> Subject: Re: [PHP] Strange Numeric Conversion...
> 
> sry... it's \\1 instead of //1 ... guess i had one to many beers :)
> 
> Red Wingate wrote:
> 
>> trim will not work, try something like:
>> 
>> $id = preg_replace("/^0+(.*)$/","//1",$id);
>> 
>> instead
>> 
>> 

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



Re: [PHP] Strange Numeric Conversion...

2004-04-02 Thread Red Wingate
sry... it's \\1 instead of //1 ... guess i had one to many beers :)

Red Wingate wrote:

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 = 11;
$id = ltrim($id, '0');
echo $id;   // Displays: 9 instead of 11 ???
This didn't work either:

$id = 11;
settype($id, 'string');
$id = ltrim($id, '0');
echo $id;   // Displays: 9 instead of 11 ???
No matter what I do, $id=11 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 11.

If PHP sees this as an octal, then why does gettype(11) = 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 = 11;
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, 11, 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


Re: [PHP] Strange Numeric Conversion...

2004-04-02 Thread Red Wingate
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 = 11;
$id = ltrim($id, '0');
echo $id;   // Displays: 9 instead of 11 ???
This didn't work either:

$id = 11;
settype($id, 'string');
$id = ltrim($id, '0');
echo $id;   // Displays: 9 instead of 11 ???
No matter what I do, $id=11 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 11.
If PHP sees this as an octal, then why does gettype(11) = 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 = 11;
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, 11, 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


Re: [PHP] Strange Numeric Conversion...

2004-04-02 Thread Monty
I tried removing the zeros, but, I get the same result:

$id = 11;
$id = ltrim($id, '0');
echo $id;   // Displays: 9 instead of 11 ???

This didn't work either:

$id = 11;
settype($id, 'string');
$id = ltrim($id, '0');
echo $id;   // Displays: 9 instead of 11 ???

No matter what I do, $id=11 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 11.

If PHP sees this as an octal, then why does gettype(11) = 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 = 11;
> 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, 11, 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



Re: [PHP] Strange Numeric Conversion...

2004-04-02 Thread Daniel Clark
Wow, thanks John !

> Number values starting with a leading zero are assumed to be octal values.
>
> Octal 11 = Decimal 9
>
> ---John Holmes...

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



RE: [PHP] Strange Numeric Conversion...

2004-04-02 Thread Jay Blanchard
[snip]
"naked"
[/snip]

Dang John, I guess I don't think octally any more!

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



RE: [PHP] Strange Numeric Conversion...

2004-04-02 Thread Jay Blanchard
[snip]
Why is this happening???

$id = 11;
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, 11, 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



Re: [PHP] Strange Numeric Conversion...

2004-04-02 Thread John W. Holmes
From: "Monty" <[EMAIL PROTECTED]>

> $id = 11;
> 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?

Number values starting with a leading zero are assumed to be octal values.

Octal 11 = Decimal 9

---John Holmes...

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