Arkane Posted December 3, 2008 Share Posted December 3, 2008 Just a quick one (I think). I have data being pulled from a database, including a number field. Problem is, this field is just the number, whereas I need to have it in a 4dp mode. I just need a quick way to add leading zeros, so that the number will always be length 4. ie 1 = 0001, 23 = 0023, 456 = 0456 Anyone able to help me? Link to comment https://forums.phpfreaks.com/topic/135263-add-leading-zeros/ Share on other sites More sharing options...
genericnumber1 Posted December 3, 2008 Share Posted December 3, 2008 <?php $str = sprintf('%04d', 1); // 0001 ?> or use printf() if you just wish to output it instead of assign it to a string. Link to comment https://forums.phpfreaks.com/topic/135263-add-leading-zeros/#findComment-704515 Share on other sites More sharing options...
Arkane Posted December 3, 2008 Author Share Posted December 3, 2008 Thanks man, that works great, cheers Link to comment https://forums.phpfreaks.com/topic/135263-add-leading-zeros/#findComment-704539 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.