English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
PHP String String Functions Manual
The vsprintf() function is used to return a formatted string
string vsprintf ( string $format , array $args )
It returns a formatted string
Unlike sprintf(), the parameters in vsprintf() are located in an array. 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, consisting of a number and "\$".
Tip:Related functions:fprintf(),vfprintf(),printf(),sprintf() and vprintf()
It returns the array value in the form of a formatted string
Number | Parameters and descriptions |
---|---|
1 | format Specify the string and how to format the variables within it Possible format values:
Additional format values. They 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. |
2 | argarray Specify the array to insert parameters |
Try the following example, formatting dates, leading zeros for integers
<?php print vsprintf("%04d-%02d-%02d", explode('-', ''1990-12-25); echo '<br>'; //Using format value %f $num1 = 123; $num2 = 456; $txt = vsprintf("%f%f",array($num1$num2)); echo $txt; ?>Test and see‹/›
Output Result
1990-12-25 123.000000456.000000