The vprintf () function outputs formatted strings.
The number format is the conversion format, starting from the percent sign ("%") to the end of the conversion character. The following possible format values:
%-Percentage sign returned
% B-binary number
% C-Characters Based on ascii values
% D-Signed decimal number
% E-resumable counting (for example, 1.5e + 3)
% U-Unsigned decimal number
% F-floating point number (local settings aware)
% F-floating point number (not local settings aware)
% O-octal values
% S-string
% X-hexadecimal (lowercase letter)
% X-hexadecimal (uppercase letters)
View instances
*/
$ Str = "hello"; // define a string
$ Number = 123; // define a value
Vprintf ("% s world. day number % u", array ($ str, $ number); // output formatted strings
// Instance 2
$ Num1 = 123; // defines the value 1
$ Num2 = 456; // defines the value 2
$ Txt = vsprintf ("% f", array ($ num1, $ num2); // output the formatted string to the variable
Echo $ txt;
/*
The printf () function outputs formatted strings.
Syntax
Printf (format, arg1, arg2, arg ++)
Parameters such as arg1, arg2, ++ are inserted to the percent sign (%) in the main string. This function is executed step by step. In the first % symbol, insert arg1, at the second % symbol, insert arg2, and so on.
*/
$ Str = "hello world"; // defines a string with spaces at the beginning and end
Printf ($ str); // output the converted result
/*
The sprintf () function writes formatted strings to a variable.
Syntax
Sprintf (format, arg1, arg2, arg ++)
*/
$ Str = "hello"; // define a string
$ Number = 123; // define a value
$ Txt = ("% s world. day number % u", $ str, $ number); // returns the formatted string to the variable
Echo $ txt; // The output result hello world. day number 123.
$ Str = "123456 abcdedfbcdef"; // define a string
Sscanf ($ str, "% [^ a-z]", $ result); // retrieves non-UPPERCASE letters
Printf ("result = % s", $ result); // output the result
/* The following code displays 11 and writes the "hello world" character string to the test.txt file */
$ Str = "hello"; // define a string
$ File = fopen ("test.txt", "w"); // open the file
Echo vfprintf ($ file, "% s world", $ str); // output data to the stream and display result 11