English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Basic PHP Tutorial

Advanced PHP Tutorial

PHP & MySQL

PHP Reference Manual

Usage and Examples of PHP vprintf() Function

    PHP String String Functions Manual

    The vprintf() function is used to output formatted strings.

Syntax

vprintf(format, argarray)

Definition and Usage

It is used to convert a string to a formatted string

Return Value

 Returns the length of the output string.

Parameter

NumberParameters and descriptions
1

format

Specify the string and how to format the variables within it

Possible format values:

  • %% - Returns a percentage sign %

  • %b - Binary number

  • %c - Character corresponding to ASCII value

  • %d - Decimal number with a sign (negative, 0, positive)

  • %e - Use lowercase scientific notation (for example 1.2e+2

  • %E - Use uppercase scientific notation (for example 1.2E+2

  • 㩵n - Decimal number without a sign (greater than or equal to 0)

  • %f - Floating-point number (local setting)

  • %F - Floating-point number (non-local setting)

  • %g - Short %e and %f

  • %G - Short %E and %f

  • %o - Octal number

  • %s - String

  • %x - Hexadecimal number (lowercase letters)

  • %X - Hexadecimal number (uppercase letters)

Additional format values. They must be placed between % and the letter (for example %.2f):

  • + (Add + or - to define the sign of the number. By default, only negative numbers are marked, and positive numbers are not marked)

  • ' (Specify what to use as padding, the default is a space. It must be used with the width specifier. For example: %'x20s (Use "x" as the padding))

  • - (Left align the variable value)

  • ][0-9](Specify the minimum width of the variable value)

  • ].[0-9](Specify the number of decimal places or the maximum string length)

Note:If multiple format values are used, they must be used in the order specified above and cannot be rearranged.

2

argarray

Specify the array to insert parameters, which will be inserted into the format string at the % symbol.

Online Example

Try the following example, using 鵽 %s to output formatted strings.

<?php
    //vprintf uses 鵽 %s to output formatted strings
   $number = 5;
   $str = "oldtoolbag.com";
   
   vprintf("There are 쥕lion users for %s.", array($number, $str));
?>
Test and see‹/›

Output Result

There are 5 million users for oldtoolbag.com.

PHP String String Functions Manual