Skip to main content
Shop Support Downloads
IBM Home Products Consulting Industries News About IBM
IBM developerWorks : Web Architecture : Education - Tutorials
Writing efficient PHP
ZIPPDF (letter)PDF (A4)e-mail
Main menuSection menuFeedbackPreviousNext
3. Tweaking PHP code

Understanding the difference between print and printf page 4 of 11

PHP developers with a background in C and C++ may frequently be tempted to use the printf function to output strings. While this works fine, it does cost more in terms of CPU usage than the similar, yet more basic print function. Strictly speaking print is not a real function but a language construct.

Don't use printf when print is sufficient. To output simple strings, use print. Generally, you should only use printf (and sprintf) when you need more control over the output format, for example, when formatting integer or floating point numbers for display.

Main menuSection menuFeedbackPreviousNext
Privacy Legal Contact