Home > Article > Backend Development > How to use sprintf function in php
Usage: 1. Create a new PHP sample file; 2. Add HTML architecture code to the file; 3. Add PHP code to the body tag and use the sprintf function; 4. Observe the effect through the browser.
Usage of sprintf function in php
Specific usage method:
1. Create a new php sample file.
2. Add html schema code in the file.
<!DOCTYPE html> <html> <head> <title>php</title> </head> <body> </body> </html>
3. Add php code in the body tag and use sprintf function.
<?php $number = 2; $str = "Shanghai"; $txt = sprintf("There are %u million cars in %s.",$number,$str); echo $txt; ?>
Replace the percent sign % symbol with a variable passed as a parameter.
4. Just observe the effect through the browser.
sprintf definition:
The sprintf() function can write a formatted string into a variable.
The above is the detailed content of How to use sprintf function in php. For more information, please follow other related articles on the PHP Chinese website!