PHP Programing language

vprint() Functions in PHP
Previous Home Next
adplus-dvertising

vprintf()

The vprintf() function outputs a formatted string.

Syntax:
vprintf(format,argarray)

In above syntax, "argarray" an array with arguments to be inserted at the % signs in the format string and "format" specifies the string and how to format the variables in it are as follows:

  • %% - Returns a percent sign
  • %b - Binary number
  • %c - The character according to the ASCII value
  • %d - Signed decimal number (negative, zero or positive)
  • %e - Scientific notation using a lowercase (e.g. 1.2e+2)
  • %E - Scientific notation using a uppercase (e.g. 1.2E+2)
  • %u - Unsigned decimal number (equal to or greather than zero)
  • %f - Floating-point number (local settings aware)
  • %F - Floating-point number (not local settings aware)
  • %g - shorter of %e and %f
  • %G - shorter of %E and %f
  • %o - Octal number
  • %s - String
  • %x - Hexadecimal number (lowercase letters)
  • %X - Hexadecimal number (uppercase letters)

Example:

<?php
$number = 20;
$str = "pocket";
vprintf("There are %u chocolates in my %s",array($number,$str));
?>

Output:

There are 20 chocolates in my pocket

vfprintf()

The vfprintf() function writes a formatted string to a specified output stream.

Syntax:
vfprintf(stream,format,argarray)

In above syntax, "stream" specifies where to write/output the string, "argarray" an array with arguments to be inserted at the % signs in the format string and "format" specifies the string and how to format the variables in it. For format refer vprintf()

Example:

<?php
$number = 20;
$str = "pocket";
$file = fopen("test.txt","w");
echo vfprintf($file,"There are %u chocolates in my %s",array($number,$str));
?>

Output:

36

vsprintf()

The vsprintf() function writes a formatted string to a variable.

Syntax:
vprintf(format,argarray)

In above syntax, "argarray" an array with arguments to be inserted at the % signs in the format string and "format" specifies the string and how to format the variables in it. For format refer vprintf()

Example:

<?php
$number = 20;
$str = "pocket";
$txt = vsprintf("There are %u chocolates in my %s",array($number,$str));
echo $txt;
?>

Output:

There are 20 chocolates in my pocket

Previous Home Next