Solved

Pre zero's in counter

Posted on 2006-06-22
2
262 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

813 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

11 Experts available now in Live!

Get 1:1 Help Now