itazev Posted April 5, 2007 Share Posted April 5, 2007 Hey ya! I searched for leading zeroes php function all the way and I found that it can be done in date functions. but what if I want to list a non-date query from mysql? lets say I have field CODE_NUMBER and it stores 5, 128, 96, 5879 ... is there a function (?) that i can use to make them appear in the html with leading zeroes like: 0005 , 0128 , 0096 , 5879 thank you Quote Link to comment Share on other sites More sharing options...
effigy Posted April 5, 2007 Share Posted April 5, 2007 printf or sprintf. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 5, 2007 Share Posted April 5, 2007 I would use the sprintf() function: <?php $orig = '5, 128, 96, 5879'; $tmp = array(); foreach (explode(',',$orig) as $num) $tmp[] = sprintf("%04d",$num); echo implode(', ',$tmp); ?> Ken Quote Link to comment Share on other sites More sharing options...
itazev Posted April 5, 2007 Author Share Posted April 5, 2007 worked! cheers mates!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.