PHP » I/O » printf()

Syntax:
void printf(string format [, mixed data, ...])
format
The string with optional format specifiers. Available format specifiers follow.
%s
String.
%d
Integer displayed as decimal number.
%b
Integer displayed as binary number.
%o
Integer displayed as octal number.
%x
Integer displayed as hexadecimal number.
%X
Integer displayed as hexadecimal number with capital letters.
%c
Character.
%f
Double.
%e
Double with scientific formatting.
%%
Percent sign.

Sends formatted text to the web browser.

This function is familiar to anyone who has done C programming. printf() takes a string with embedded type specifiers, where formatted data should be inserted. That should be followed by any number of arguments that contain the data that is to be inserted in the string.

Examples

Code:
<?php

$s = "world";
$temp = 72;

printf("Hello %s! Right now the temperature is %d F. 0x%x seconds have passed since January 1, 1970.",
   $s, $temp, time());

?>
Output:
Hello world! Right now the temperature is 72 F. 0x406b4d70 seconds have passed since January 1, 1970.
Explanation:

The code shows printf() in use with the %s, %d, and %x type specifiers.

See Also: