How can printf be used to fill spaces as padding in PHP?
When using printf in PHP, you can specify a width for the output, which will add padding spaces to align the text. To fill spaces as padding, you can use the %s format specifier along with a width parameter. This will ensure that the output is padded with spaces to reach the specified width.
$name = "John";
$age = 30;
printf("Name: %10s, Age: %5d", $name, $age);
Keywords
Related Questions
- How can PHP documentation resources like opendir(), readdir(), closedir(), and glob() be effectively utilized for file manipulation tasks?
- What are the potential pitfalls of using cookies to restrict multiple votes on a website?
- What potential issues can arise when comparing and inserting data from multiple arrays in PHP?