vfprintf
PHP function
Edit on GitHub ✎
(PHP 5, PHP 7, PHP 8)
Write a formatted string to a stream
Description
vfprintf(resource $stream, string $format, array $values): int
Write a string produced according to format to the stream resource specified by stream.
Operates as fprintf() but accepts an array of arguments, rather than a variable number of arguments.
Parameters
streamvalues
Return Values
Returns the length of the outputted string.
Errors/Exceptions Vsprintf
Changelog Vsprintf
Examples
vfprintf(): zero-padded integers
php
<?php
if (!($fp = fopen('date.txt', 'w')))
return;
$year = 2025;
$month = 5;
$day = 6;
vfprintf($fp, "%04d-%02d-%02d", array($year, $month, $day));
// will write the formatted ISO date to date.txt
?>