
-----------------------------------
beno
Tue Oct 28, 2008 8:00 pm

0's problem
-----------------------------------
when the user input "00" or "000" or "0000", ect..
how can you ask the computer to treat them as only one "0"??

do it in php...

$a = $_REQUEST['a'];

-----------------------------------
Insectoid
Tue Oct 28, 2008 8:03 pm

RE:0\'s problem
-----------------------------------
convert to a string, check if every element in the string equals zero, then initialize to 0 and convert back to integer?

-----------------------------------
beno
Tue Oct 28, 2008 8:23 pm

RE:0\'s problem
-----------------------------------
i have just learned php for a few days..
how to convert a int to string, then convert it back??
=)

-----------------------------------
Tony
Tue Oct 28, 2008 8:25 pm

RE:0\'s problem
-----------------------------------
"00" _is_ a string. Simply typecast it into the integer.

Assuming you are trying to get rid of the leading zeros from a string.

-----------------------------------
beno
Tue Oct 28, 2008 8:31 pm

RE:0\'s problem
-----------------------------------


is that how you convert it?

but, is there any method for php that can check characters? (like java, uses charAt())

-----------------------------------
Insectoid
Tue Oct 28, 2008 8:49 pm

RE:0\'s problem
-----------------------------------
I have no idea, my example was based on general programming.

-----------------------------------
btiffin
Tue Oct 28, 2008 8:52 pm

Re: 0's problem
-----------------------------------
Yes;  (integer) cast will also work, the intval() function may be worth looking into.  And sometimes there is is no need to cast at all as PHP is rife with type coercion.
$ php -r '$a = "12"; echo $a + 3 . "\n";'
15

Cheers

-----------------------------------
jeffgreco13
Wed Oct 29, 2008 2:56 am

Re: 0's problem
-----------------------------------
theres many ways to do it really, its pretty much as simple as this though...



