What are the Formatting and Printing Strings available in PHP?

What are the Formatting and Printing Strings available in PHP?

The formatting and printing strings available in PHP are printf() and sprintf(). These can be used to format the string in different ways. When we need to format a string and print it, printf() function is used. If we have to format and return the string sprintf() is used.

The format specifiers are:

  • %b - binary
  • %c - ASCII character
  • %d - signed decimal number
  • %e - scientific number
  • %u - unsigned decimal number
  • %f - float with local settings
  • %F - float without local settings
  • %o - octal number
  • %x - lowercase hexadecimal
  • %X - uppercase hexadecimal

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.