|
|
 |
fprintf (PHP 5) fprintf -- Write a formatted string to a stream Descriptionint fprintf ( resource handle, string format [, mixed args [, mixed ...]] )
Write a string produced according to format
to the stream resource specified by handle.
format is described in the documentation for
sprintf().
Returns the length of the outputted string.
See also: printf(),
sprintf(),
sscanf(), fscanf(),
vsprintf(), and
number_format().
Examples
Example 1. fprintf(): zero-padded integers |
<?php
if (!($fp = fopen('date.txt', 'w')))
return;
fprintf($fp, "%04d-%02d-%02d", $year, $month, $day);
?>
|
|
Example 2. fprintf(): formatting currency |
<?php
if (!($fp = fopen('currency.txt', 'w')))
return;
$money1 = 68.75;
$money2 = 54.35;
$money = $money1 + $money2;
$len = fprintf($fp, '%01.2f', $money);
echo "wrote $len bytes to currency.txt";
?>
|
|
User Contributed Notes
fprintf
aidan at php dot net
30-May-2004 12:35
This functionality is now implemented in the PEAR package PHP_Compat.
More information about using this function without upgrading your version of PHP can be found on the below link:
http://pear.php.net/package/PHP_Compat
| |