The difference between printf and sprintf is that printf outputs a formatted string, while sprintf returns a formatted string.
The difference between printf and sprintf is that printf outputs a formatted string, while sprintf returns a formatted string.
For example, the following will output the http://www.dayanmei.com
[Php]
Printf ('http: // www. % 1 $ s. % 2 $ s', 'dayanmei', 'com ');
?>
[/Php]
In this way, there is no output
[Php]
Sprintf ('http: // www. % 1 $ s. % 2 $ s', 'dayanmei', 'com ');
?>
[/Php]
You can format and output a string in this way.
[Php]
$ S = sprintf ('http: // % 3 $ s. % 1 $ s. % 2 $ s', 'dayanmei', 'com', 'WWW ');
Echo $ s;
?>
[/Php]
Use of printf and sprintf
As shown in the preceding figure, you can specify the order of parameter calls and the parameter type.
% 3 indicates that the third parameter is called. if not specified, the third parameter is called in sequence by default.
For example
[Php]
Printf ('http: // % s. % s. % s', 'dayanmei', 'com', 'WWW ');
Echo $ s;
?>
[/Php]