PHP Printf function

The printf() function is used to give formatted strings as output.

PHP echo and print statements also outputs strings however these are not functions like printf(). echo and print are language constructs.

The method of taking input in print is different where you may provide a format string and then list all required input. Its like in C/C++.

At first look this seems slightly different but as such printf() is a function, in some special cases it can work better.

Example of PHP printf:

The arg1, arg2, ++ parameters will be inserted at percent (%) signs in the main string. This function works “step-by-step”. At the first % sign, arg1 is inserted, at the second % sign, arg2 is inserted, etc.

See Also PHP Echo | PHP print

Was this article helpful?

Related Articles

Leave A Comment?