Home >Backend Development >PHP Tutorial >vsprintf() function in PHP

vsprintf() function in PHP

王林
王林forward
2023-08-28 09:45:061414browse

vsprintf() function in PHP

vsprint() function returns a formatted string.

Syntax

vsprintf(format,argarray)

Parameters

  • Format - Specifies the string and how to format the variables within it.

  • The following are possible format values ​​-

    • %% - Returns the percent sign

    • %b - Binary number

    • %c - Convert the character to an ASCII value

    • %d - Signed decimal number (negative, zero, or positive)

    • %e - Use Scientific notation with lowercase letters (e.g. 1.2e 2)
    • %E - Scientific notation with uppercase letters (e.g. 1.2E 2)

    • %u - Unsigned decimal number (equal to or greater than zero)

    • %f - Float Points (local settings aware)

    • %F > - Floating point (local settings not supported)

    • %g - The shorter of %e and %f

    • %G - The shorter of %E and %f

    • %o - Octal number

    • ##%s - String

    • %x - Hexadecimal number (lowercase letters)

    • %X - Hexadecimal number (capital letters)

  • arg - an array containing the arguments to insert the % symbol into the format string

Return

The vsprintf() function returns a value in the form of a formatted string.

Example

The following is an example -

Real-time demonstration

<?php
$a = 6567;
$b = 8976;
$res = vsprintf("%f</p><p>%f",array($a,$b));
echo $res;
?>

Output

6567.000000
8976.000000

The above is the detailed content of vsprintf() function in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete