Home  >  Article  >  Backend Development  >  Application of sprintf() function in PHP

Application of sprintf() function in PHP

一个新手
一个新手Original
2017-09-07 09:22:051517browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn