PHP fprintf() Function

The fprintf() function writes a formatted string to a specified output stream (example: file or database). The arg1, arg2, ++ parameters will be inserted at percent (%) signs in the main string. This function works "step-by-step". At the first % sign, arg1 is inserted, at the second % sign, arg2 is inserted, etc.

int fprintf ( resource $handle , string $format [, mixed $args [, mixed $... ]] )

Write a string produced according to format to the stream resource specified by handle.

Example -

Example #1 fprintf(): zero-padded integers

Example #2 fprintf(): formatting currency

ParameterDescription
handleA file system pointer resource that is typically created using fopen().
formatSee sprintf() for a description of format.

Returns the length of the string written.