format a number to fit xxxx

Hi

I want to format a number to fill a 4 digit space, but not like
0003
0100
0001


I want it to use dashes, or another character of my choice? such as
---3
-100
---1

is this possible?

Neil
LVL 3
Neil ThompsonSenior Systems DeveloperAsked:
Who is Participating?
 
RoonaanCommented:
$formatted = sprintf('%-4d', $number);

or

$formatted = sprintf('%04d', $number);

-r-
0
 
snoyes_jwCommented:
http://www.php.net/strpad

Pass '-' as the third parameter, and STR_PAD_LEFT as the fourth.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.