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

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

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

Comments

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

Why not use the built in str_pad() function?