tags:

views:

85

answers:

3

like

%2$s

%04d

%01.2f

%'#10s

etc.

can you give me some more commonly used combination?

+7  A: 

A type specifier that says what type the argument data should be treated as. Possible types:

  • % - a literal percent character. No argument is required.
  • b - the argument is treated as an integer, and presented as a binary number.
  • c - the argument is treated as an integer, and presented as the character with that ASCII value.
  • d - the argument is treated as an integer, and presented as a (signed) decimal number.
  • e - the argument is treated as scientific notation (e.g. 1.2e+2). The precision specifier stands for the number of digits after the decimal point since PHP 5.2.1. In earlier versions, it was taken as number of significant digits (one less).
  • u - the argument is treated as an integer, and presented as an unsigned decimal number.
  • f - the argument is treated as a float, and presented as a floating-point number (locale aware).
  • F - the argument is treated as a float, and presented as a floating-point number (non-locale aware). Available since PHP 4.3.10 and PHP 5.0.3.
  • o - the argument is treated as an integer, and presented as an octal number.
  • s - the argument is treated as and presented as a string.
  • x - the argument is treated as an integer and presented as a hexadecimal number (with lowercase letters).
  • X - the argument is treated as an integer and presented as a hexadecimal number (with uppercase letters).

http://us.php.net/sprintf

meder
+2  A: 

They are in length described in the manual page for sprintf.

Bombe
+4  A: 

I don't want this to come as a RTFM, but PHP has some of the cleanest and easiest to use documentation I've ever seen. Here's a tip for this question, and just about any other PHP documentation question:

  • Open browser
  • Type php.net/function_name in your location bar
  • Press Enter

If you type a valid function name it takes you directly to the documentation for that function. This is exactly what meder did, and he cut and pasted the documentation directly here. If you mistype or don't know the spelling, as long as you're reasonably close, PHP will offer a list of suggestions.

The StackOverflow community should be less of a "read the manual for me" community, and more of a "I've already tried, and I need help".

Hope this helps you for future questions.

hobodave
You’re so damn right. Reading documentation is something that’s apparently considered a waste of time by lots of people asking questions on stackoverflow.
Bombe
this is not the answer
coderex