Possible Duplicates:
PHP sprintf() and printf() functions
Why use sprintf function in PHP?
Printf and sprintf where exactly used in php? give one example?
Possible Duplicates:
PHP sprintf() and printf() functions
Why use sprintf function in PHP?
Printf and sprintf where exactly used in php? give one example?
printf
function in php is used to output a formatted string
For example:
<?php
$format = 'I have %d questions to %s';
printf($format, 2, 'answer');
?>
This will output as follows:
I have 2 questions to answer
sprintf
function in php is used to return a formatted string.
For Example:
<?php
$format = 'I have %d questions to %s';
$a_string = sprintf($format, 2, 'answer');
echo $a_string;
?>
This will output as follows: I have 2 questions to answer
In the second example sprintf
function returns a formatted string and gets stored into the variable $a_string
.