DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Zeropad A Number

  • submit to reddit
        Pads a string with 0's until the given length limit is met

function zeropad($number, $limit) {
  return (strlen($number) >= $limit) ? $number : zeropad("0" . $number, $limit);


Snippets Manager replied on Mon, 2012/05/07 - 2:33pm

Why not use the built in str_pad() function?