How to use sprintf() In PHP
To display formatted text in PHP, use printf() or sprintf(). Provide a format string with placeholders for variables, followed by the variables themselves. printf() prints directly to the output, while sprintf() returns the formatted string.
Example
<?php
$string = "w3wiki!!";
// Creating the formatted string using sprintf
$formattedString = sprintf("Printing the string: %s", $string);
// Printing the formatted string
print $formattedString;
?>
Output:
Printing the string: w3wiki!!
How to display text with a PHP script ?
PHP allows us to display the text in various formats using various inbuilt methods.
Contact Us