You are here

20 February 2011
This tutorial shows how to add or append zeros before numbers. You might need this if you want to make folders named by numbers and you want them to be in right order when browsing the folder with your file browser.
Source code viewer
  1. // How many chars will be in the string.
  2. $fill = 6;
  3. // The number.
  4. $number = 56;
  5. // With str_pad function the zeros will be added.
  6. echo str_pad($number, $fill, '0', STR_PAD_LEFT);
  7.  
  8. // The result: 000056
Programming Language: PHP