printf

Outputs one or more strings

Provides a success/fail return value

Takes a string with format component to output the arguments

 

printf($stringFormat, $arg1 .. $arg) ;

 

Format specifiers comprise of a % symbol followed by a lower case letter

Letter Description
c Argument is treated like an integer and provides ASCII character with that value
d Argument is treated like an integer and presented as a number
f Argument is treated like a float and presented as a floating point number
s Argument is treated and presented as a string

 

%s

 

To left justify, precede the string specifier with a hyphen -

 

Number of places can be set:

%10.2f means a floating point number with a:

  • width of 10 places
    • comprising of:
      • 7 integers
      • 1 decimal point
      • 2 decimals precision

Displays:

This is a string followed by an integer 17

Leave a Reply