Web developer, Norwich - Clive Portman

Add leading zeros using PHP

Published under PHP

Published on Monday 13th December 2010

Useful for catalogue numbers, add leading zeros using str_pad:

$i = 56;
$cat = str_pad($i, 5, “0″, STR_PAD_LEFT);
echo $cat; // displays 00056