Strings In Depth12 / 18
Up next

Pad to a width

<?php
declare(strict_types=1);
// pad on the left to width 3
echo str_pad("7", 3, "0", STR_PAD_LEFT), "\n";
// pad on both sides
echo str_pad("hi", 6, ".", STR_PAD_BOTH), "\n";
What you're solving

str_pad with a direction flag