O'Reilly logo

Programming PHP, 3rd Edition by Peter MacIntyre, Kevin Tatroe, Rasmus Lerdorf

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

printf

Synopsis

int printf(string format[, mixed arg1 ...])

Outputs a string created by using format and the given arguments. The arguments are placed into the string in various places denoted by special markers in the format string.

Each marker starts with a percent sign (%) and consists of the following elements, in order. Except for the type specifier, the specifiers are all optional. To include a percent sign in the string, use %%.

  1. An optional sign specifier that forces a sign (– or +) to be used on a number. By default, only the – sign is used on a number if it’s negative. Additionally, this specifier forces positive numbers to have the + sign attached.

  2. A padding specifier denoting the character to use to pad the results to the appropriate string size (given below). Either 0, a space, or any character prefixed with a single quote may be specified; padding with spaces is the default.

  3. An alignment specifier. By default, the string is padded to make it right-justified. To make it left-justified, specify a dash (-) here.

  4. The minimum number of characters this element should contain. If the result would be less than this number of characters, the above specifiers determine the behavior to pad to the appropriate width.

  5. For floating-point numbers, a precision specifier consisting of a period and a number; this dictates how many decimal digits will be displayed. For types other than float, this specifier is ignored.

  6. Finally, a type specifier. This specifier tells printf() what type of data ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required