Solved

Pre zero's in counter

Posted on 2006-06-22
2
265 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Checking https returns 301 21 59
Increase counter and attr inside a while loop 15 37
MySQL-Design Help 12 44
Get data from two MySQL tables 6 27
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…
This article discusses how to create an extensible mechanism for linked drop downs.
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 dynamically set the form action using jQuery.

733 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