PHP vfprintf() function

example

Write the text to the text file named "test.txt":

<?php
$number = 9;
$str = "Beijing";
$file = fopen("test.txt","w");
echo vfprintf($file,"There are 쥕lion bicycles in %s.",array($number,$str));
?>

The above code will output:

40

The following text will be written to the file "test.txt":

There are 9 million bicycles in Beijing.

definition and usage

The vfprintf() function writes the formatted string to the specified output stream (for example: file or database).

Unlike fprintf(), the parameters in vfprintf() 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.

মুক্তপত্র:if % symbol is more than arg parameter, then you must use a placeholder. The placeholder is inserted after the % symbol, composed of a number and "\$". See example 2.

related functions:

syntax

vfprintf(stream,format,argarray)
parameter description
stream অপরিহার্য
format

অপরিহার্য

সম্ভাব্য ফরম্যাট মান

  • %% - % সংজ্ঞা ফিরিয়ে দেয়
  • %b - দ্বিপদক্ষম নম্বর
  • %c - ASCII মানের অক্ষর
  • %d - পজিটিভ নেগেটিভ অথবা 0 নিয়ে দশমিক নম্বর
  • %e - ছোট হাইপোথেটিক্যাল ক্রমাঙ্ক (যেমন 1.2e+2)
  • %E - বড় হাইপোথেটিক্যাল ক্রমাঙ্ক (যেমন 1.2E+2)
  • 踃জিটিভ নম্বর নিয়ে না যোগ করা দশমিক নম্বর (অথবা 0)
  • %f - ফ্লোটিং পয়েন্ট (লোকাল সেটিং)
  • %F - ফ্লোটিং পয়েন্ট (নোট লোকাল সেটিং)
  • %g - ছোট হাইপোথেটিক্যাল %e এবং %f
  • %G - ছোট হাইপোথেটিক্যাল %E এবং %f
  • %o - অষ্টদশমান নম্বর
  • %s - স্ট্রিং
  • %x - হেক্সাডেসিমাল নম্বর (ছোট অক্ষর)
  • %X - হেক্সাডেসিমাল নম্বর (বড় অক্ষর)

অতিরিক্ত ফরম্যাট মান

  • + (নম্বরের পূর্বে + বা - টি যোগ করে নম্বরের পজিটিভ অথবা নেগেটিভ সংজ্ঞা করে।ডিফল্টভাবে, শুধুমাত্র নেগেটিভ নম্বরকেই টি টাগ করা হয়, পজিটিভ নম্বরকে টি টাগ করা হয় না)
  • ' (规定使用什么作为填充,默认是空格。它必须与宽度指定器一起使用。例如:%'x20s(使用 "x" 作为填充))
  • - (বাম সজ্জীকরণ করা হবে)
  • [0-9] (পরিমাণকে নির্ধারণ করা হবে)
  • [0-9] (দশমিক সংখ্যা নির্ধারণ করা হবে কিংবা সর্বোচ্চ স্ট্রিং-এর দৈর্ঘ্য)

মুক্তপত্র:একাধিক ফরম্যাট মানা ব্যবহার করা হলে, তারা উপরোক্ত ক্রমে বার্তায় থাকবে।

argarray অপরিহার্য। একটি পারামিটার সহ একটি আইনসংকলন, যা পরে প্রবেশ করবে। format স্ট্রিং-এর %% সংকেতে।

প্রযুক্তিগত বিবরণ

ফলাফল: লেখা হওয়া চিহ্নিত স্ট্রিং-এর দৈর্ঘ্য ফিরিয়ে দেয়。
PHP সংস্করণ: 5+

আরও উদাহরণ

উদাহরণ 1

টেক্সট ফাইলে লেখা হবে:

<?php
$num1 = 123;
$num2 = 456;
$file = fopen("test.txt","w");
vfprintf($file,"%f%f",array($num1,$num2));
?>

নিম্নলিখিত টেক্সট "test.txt" ফাইলে লেখা হবে:

123.000000456.000000

উদাহরণ 2

প্রতিস্থাপক ব্যবহার করুন:

<?php
$number = 123;
$file = fopen("test.txt","w");
vfprintf($file,"With 2 decimals: %1$.2f
\nকোনো দশমিক নেই: %1$u",array($number));
?>

নিম্নলিখিত টেক্সট "test.txt" ফাইলে লেখা হবে:

2 দশমিক নেই: 123.00
কোনো দশমিক নেই: 123

উদাহরণ 3

সমস্ত সম্ভাব্য ফরম্যাট মানা printf() দ্বারা প্রদর্শিত করুন:

<?php
$num1 = 123456789;
$num2 = -123456789;
$char = 50; // ASCII 字符 50 是 2
// 注释:格式值 "%%" 返回百分号
printf("%%b = %%b <br>", $num1); // 二进制数
printf("%%c = %%c <br>", $char); // ASCII 字符
printf("%%d = %%d <br>", $num1); // 带符号的十进制数
printf("%%d = %%d <br>", $num2); // 带符号的十进制数
printf("%%e = %%e <br>", $num1); // 科学计数法(小写)
printf("%%E = %%E <br>", $num1); // 科学计数法(大写)
printf("%鑾u <br>", $num1); // Unsigned Decimal Number (Positive)
printf("%鑾u <br>", $num2); // Unsigned Decimal Number (Negative)
printf("%%f = %f <br>", $num1); // Floating Point Number (Localized)
printf("%%F = %F <br>", $num1); // Floating Point Number (Not Localized)
printf("%%g = %g <br>", $num1); // Shorter than %e and %f
printf("%%G = %G <br>", $num1); // Shorter than %E and %f
printf("%%o = %o <br>", $num1); // Octal Number
printf("%%s = %s <br>", $num1); // String
printf("%%x = %x <br>", $num1); // Hexadecimal Number (Lowercase)
printf("%%X = %X <br>", $num1); // Hexadecimal Number (Uppercase)
printf("%%+d = %+d <br>", $num1); // Positive Sign Indicator
printf("%%+d = %+d <br>", $num2); // Negative Sign Indicator
?>

Run Example