What are some common pitfalls when using printf() in PHP for formatted output?

One common pitfall when using printf() in PHP for formatted output is forgetting to properly escape any special characters within the format string. This can lead to unexpected behavior or errors in the output. To solve this issue, make sure to use the % character to escape any percent signs or other special characters within the format string.

// Incorrect usage of printf without escaping special characters
$name = "John";
printf("Hello, %s! Your score is 50%", $name); // Incorrect usage

// Corrected usage of printf with escaped special characters
$name = "John";
printf("Hello, %s! Your score is 50%%", $name); // Corrected usage with escaped percent sign