This is a discussion on "incrementing variables with leading zeros" within the PHP Forum section. This forum, and the thread "incrementing variables with leading zeros are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
incrementing variables with leading zeros
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
incrementing variables with leading zeros
Not sure if this got posted last time I tried.
Here is the code in question; *[code]* <? if ($picnumber == 001) { echo '<center><a href="index.html"><img src="buttons/home.gif" </a><a href="pic.php?picnumber='.++$picnumber.'"><img src="buttons/next.gif" </a></center>'; } ?> *[code]* The problem is that I need the incremented result for $picnum to equal "002" but it increments to "2". Is there another way to increment or a way to initialize the variable so it retains the leading zeros and always keep a three digit number? Thanks Saxman |
|
|
|
||||
|
Re: incrementing variables with leading zeros
use a string rather than a numerical datatype.
I don't do PHP but I hope you'll understand this pseudo:
number = number & "" (in ASP) $number = $number.'' (I think, in PHP) Then, all you gotta do is: [code]<? if ($picnumber == 001) { echo '<center><a href="index.html"><img src="buttons/home.gif" </a><a href="pic.php?picnumber='.++Digits($picnumber,2).'"><img src="buttons/next.gif" </a></center>'; } ?>[code]
Last Blog Entry: Random String in Javascript (Apr 21st, 2008)
Last edited by spinal007; Jan 17th, 2007 at 08:55. |
|
||||
|
Re: incrementing variables with leading zeros
Quote:
I think!
Last Blog Entry: Random String in Javascript (Apr 21st, 2008)
|
|
|||
|
Re: incrementing variables with leading zeros
$val = sprintf("%03d",$val+1);
will take what's in $val, add 1 to it, format it to 3 digits leading 0 filled and put it back in $val. |
|
||||
|
Re: incrementing variables with leading zeros
Quote:
LOL, I'll go back to the ASP section
Last Blog Entry: Random String in Javascript (Apr 21st, 2008)
|
![]() |
| Tags |
| operator |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Incrementing numbers | RubyRue | ASP.NET Forum | 3 | Mar 12th, 2008 03:25 |
| kerning, leading, and justified text? | PicoDeath | Web Page Design | 7 | Jan 16th, 2008 08:29 |
| Create templates for the leading edge Terapad.com | Terapad | Job Opportunities | 0 | Aug 9th, 2007 12:57 |
| Web Developer needed for Leading Dance Label | Big fish Digital | Job Opportunities | 0 | Apr 27th, 2007 11:54 |
| Unable to get correct leading | Audioz | Web Page Design | 4 | Nov 14th, 2004 19:32 |