Build strings with sprintf
sprintf() puts values into a template and returns the string. printf() prints it.
PHP · Build strings with sprintfBeginner
$s = sprintf('%s has %d items, total %.2f', 'Cart', 3, 59.5); // Cart has 3 items, total 59.50
$id = sprintf('INV-%05d', 42); // INV-00042
$pct = sprintf('%d%%', 80); // 80%
$col = sprintf('#%02x%02x%02x', 255, 128, 0); // #ff8000
printf("%-10s|%6.1f\n", 'Left', 3.14159); // padded columnssprintfprintfformat