Solved

Pre zero's in counter

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
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 …

920 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

15 Experts available now in Live!

Get 1:1 Help Now