printf

(PHP 4, PHP 5)

printfВыводит отформатированную строку

Описание

int printf ( string $format [, mixed $args [, mixed $... ]] )

Выводит строку, отформатированную в соответствии с аргументом format.

Список параметров

format

Описание параметра format смотрите в описании функции sprintf().

args

...

Возвращаемые значения

Возвращает длину выведенной строки.

Смотрите также

  • print - Выводит строку
  • sprintf() - Возвращает отформатированную строку
  • vprintf() - Выводит отформатированную строку
  • sscanf() - Разбирает строку в соответствии с заданным форматом
  • fscanf() - Обрабатывает данные из файла в соответствии с форматом
  • flush() - Сброс буфера вывода

Коментарии

Be careful:
printf ("(9.95 * 100) = %d \n", (9.95 * 100));

'994'

First %d converts a float to an int by truncation.

Second floats are notorious for tiny little rounding errors.
1999-12-05 04:27:37
http://php5.kiev.ua/manual/ru/function.printf.html
You can use this function to format the decimal places in a number:

$num = 2.12;
printf("%.1f",$num);

prints:

2.1

see also: number_format()
2001-10-11 20:54:11
http://php5.kiev.ua/manual/ru/function.printf.html
[Editor's Note: Or just use vprintf...]

If you want to do something like <?php printf('There is a difference between %s and %s', array('good''evil')); ?> (this doesn't work)  instead of <?php printf('There is a difference between %s and %s''good''evil'); ?> you can use this function:

<?php
function printf_array($format$arr)
{
    return 
call_user_func_array('printf'array_merge((array)$format$arr));
}
?>

Use it the following way:
<?php
$goodevil 
= array('good''evil');
printf_array('There is a difference between %s and %s'$goodevil);
?>
and it will print:
There is a difference between good and evil
2005-04-10 09:15:49
http://php5.kiev.ua/manual/ru/function.printf.html
A few things to note about printf:
1. The definition of specifier g (or G) is often wrongly stated as being "use e or f (or E or f), whichever results in the shorter string". The correct rule is given in the documentation and it does not always give this result. 
2. For g/G/h/H, trailing zeros after the decimal point are removed (but not a zero just after the decimal point, in the e/E style).
3. g/G are locale-aware whether the e/E or f style is produced.
4. For b/o/x/X/u (that is, all integer styles except d) the result shown for negative values is the twos complement form of the number, 2**32 + v, where v is the (negative) value.
2024-08-24 14:24:59
http://php5.kiev.ua/manual/ru/function.printf.html

    Поддержать сайт на родительском проекте КГБ