Formatting Strings with PHP
Until now, we have simply printed any strings that we want to display directly to the browser. PHP provides two functions that allow you first to apply formatting, whether to round doubles to a given number of decimal places, define alignment within a field, or display data according to different number systems. In this section, you will look at a few of the formatting options provided by printf() and sprintf().
Working with printf()
If you have any experience with a C-like programming language, you will be familiar with the printf() function. The PHP version is similar but not identical to the C function. The PHP printf() function requires a string argument, known as a format control string. It also accepts additional ...
Get Sams Teach Yourself PHP, MySQL® and Apache All in One now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.