English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
PHP String String Functions Manual
The vfprintf() function is used to write formatted strings to a specified output stream (such as a file or database).
vfprintf(stream, format, argarray)
It is used to convert formatted strings to a specific output
Different from fprintf(), the parameters in vfprintf() are located in an array. The array elements will be inserted into the main string at the percentage (%) symbol. This function is executed step by step. At the first % symbol, the first array element is inserted, at the second % symbol, the second array element is inserted, and so on.
Note:If there are more % symbols than arg parameters, you must use placeholders. Placeholders are inserted after the % symbol, composed of numbers and "\$". See the example 2.
Tip:Related functions:fprintf(), printf(),sprintf(),vprintf() andvsprintf()
Returns the length of the output string.
Number | Parameters and descriptions |
---|---|
1 | stream Required. Specify where to write/Output string |
2 | format Required. Specify the string and how to format the variables within it Possible format values:
Additional format values. Must be placed between % and the letter (for example %.2f):
Note:If multiple of the above format values are used, they must be used in the order specified above and cannot be mixed. |
3 | argarray Required. Used to specify the array of parameters to be inserted, which will be inserted into the format string at the % symbol position. |
Try the following example, write some text to a file:
<?php //Write some text to a file: $input1 = 123; $input2 = 456; $file = fopen("sample.txt","r"); vfprintf($file,"%f%f",array($input1$input2)); ?>