Welcome to WebmasterWorld Guest from 54.235.25.206

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Addition with php

problem with zero's

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

Full Member

10+ Year Member

joined:Apr 4, 2002
posts:236
votes: 0


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 Sept 8, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Mar 6, 2002
posts:1092
votes: 0


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


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

Full Member

10+ Year Member

joined:Apr 4, 2002
posts:236
votes: 0


THANK YOU

That did the trick.

dhdweb

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 22, 2002
posts:1782
votes: 0


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

would work as well.

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members