homepage Welcome to WebmasterWorld Guest from 54.211.190.232
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Website
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Addition with php
problem with zero's
dhdweb




msg:1272057
 11:05 pm on Sep 8, 2002 (gmt 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

 

Lisa




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

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


if(strlen($newvar)==1)
$newvar = "0" . $newvar;

dhdweb




msg:1272059
 11:29 pm on Sep 8, 2002 (gmt 0)

THANK YOU

That did the trick.

dhdweb

andreasfriedrich




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

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

would work as well.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved