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

Application of sprintf() function in PHP

一个新手
Release: 2023-03-15 19:18:01
Original
1553 people have browsed it

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;
?>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template