Skip to content

Formatting

String formatting allows creating formatted output.

Common functions include:

  • printf()
  • sprintf()
$name = "John";
$age = 30;
printf("%s is %d years old", $name, $age);
$message = sprintf("Price: %.2f", 10.5);
echo $message;