Solved

Pre zero's in counter

Posted on 2006-06-22
2
255 Views
Last Modified: 2012-06-21
hi,

is there a simple way to add pre-zero's to an integer?

i want to count till 1000 but i do not want to just count from 1 to 1000, i want to count from 0001 to 1000.
i know i can do this the long way by checking its length and for each length that its smaller then 4 add a 0 infront.
but i was wondering if there was an easy way for it.
0
Comment
Question by:PatrickAdrichem
2 Comments
 
LVL 36

Accepted Solution

by:
Zyloch earned 50 total points
ID: 16957781
Hi PatrickAdrichem,

How about using:

$num = 1;
$str_num = str_pad($num, 4, '0', STR_PAD_LEFT);

And then use intval() when you need to increment

Regards,
Zyloch
0
 
LVL 5

Author Comment

by:PatrickAdrichem
ID: 16957805
works perfectly thanks!!

this is what i needed it for:

http://www.bodyvitaal.nl/new/onderzoek/admincp/colourchart.php
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now