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 Link to comment https://forums.phpfreaks.com/topic/45759-solved-str-to-int-34-0034-leading-zeroes/ Share on other sites More sharing options...
effigy Posted April 5, 2007 Share Posted April 5, 2007 printf or sprintf. Link to comment https://forums.phpfreaks.com/topic/45759-solved-str-to-int-34-0034-leading-zeroes/#findComment-222265 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 Link to comment https://forums.phpfreaks.com/topic/45759-solved-str-to-int-34-0034-leading-zeroes/#findComment-222266 Share on other sites More sharing options...
itazev Posted April 5, 2007 Author Share Posted April 5, 2007 worked! cheers mates!! Link to comment https://forums.phpfreaks.com/topic/45759-solved-str-to-int-34-0034-leading-zeroes/#findComment-222295 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.