[PHP] Pad a number with leading zeros

Created on November 30, 2026

Use sprintf with a zero-padded format such as %08d. In this example, 123 becomes a string that is eight digits wide.

<?php

$number = 123;
echo sprintf('%08d', $number);
00000123
PHP