Home > Article > Backend Development > Application of sprintf() function in PHP
The example replaces the percent sign (%) symbol with a variable passed as a parameter:
<?php $number = 2; $str = "Shanghai"; $txt = sprintf("There are %u million cars in %s.",$number,$str); echo $txt; ?>
sprintf() function writes the formatted string into the variable. The arg1, arg2, ++ parameters will be inserted into the main string at the percent sign (%) symbol. This function is executed step by step. At the first % sign, insert arg1, at the second % sign, insert arg2, and so on.
The above is the detailed content of Application of sprintf() function in PHP. For more information, please follow other related articles on the PHP Chinese website!