Welcome to WebmasterWorld Guest from 54.145.209.34

Forum Moderators: coopster & jatar k

Addition with php

problem with zero's

   
11:05 pm on Sep 8, 2002 (gmt 0)

10+ Year Member



I have a function that takes a var and adds 1

The problem is this:
The var starts as 01, I need to add 1 and have the output be 02 and so on untill 10 when the begining 0 will be dropped.

I am still new to PHP and some help with this one.

This is what I am using now:

<? $new-var = $some-var + 01 ?>

Thanks in advance,
dhdweb

11:21 pm on Sep 8, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Test to see if $newvar is less then 2 digits.


if(strlen($newvar)==1)
$newvar = "0" . $newvar;
11:29 pm on Sep 8, 2002 (gmt 0)

10+ Year Member



THANK YOU

That did the trick.

dhdweb

11:38 pm on Sep 8, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$var = sprintf [php.net]("%02d", $var);

would work as well.

 

Featured Threads

Hot Threads This Week

Hot Threads This Month