function vfprintf
vfprintf function သည် format specifier များနှင့်အညီ format ချထားသော string တစ်ခုကို file stream ထဲသို့ ရေးသွင်းသည်။ ပထမသော် parameter အဖြစ် file resource ကို၊ ဒုတိယအချက်အနေဖြင့် format string ကို၊ တတိယအချက်အနေဖြင့် အစားထိုးရန် argument များပါသော array ကို လက်ခံသည်။ Format string အတွင်း၌ အထူးသင်္ကေတများ (format specifiers) ကို အသုံးပြုထားပြီး ၎င်းတို့သည် % သင်္ကေတဖြင့် စတင်ကာ output ၏ format ကို ထိန်းချုပ်ပေးသည်။
Syntax
phpvfprintf(resource $handle, string $format, array $args): int
Format Specifiers
| Specifier | ဖော်ပြချက် |
|---|---|
%s |
String |
%d |
Signed integer (decimal) |
%u |
Unsigned integer (decimal) |
%f |
Floating-point number (locale aware) |
%F |
Floating-point number (non-locale aware) |
%c |
ASCII code ဖြင့် character |
%x |
Integer (hexadecimal, lowercase) |
%X |
Integer (hexadecimal, uppercase) |
%o |
Integer (octal) |
%b |
Integer (binary) |
%e |
Scientific notation (lowercase) |
%E |
Scientific notation (uppercase) |
%g |
Short form of %e or %f |
%G |
Short form of %E or %F |
%% |
Percent sign |
ဥပမာ
File ထဲသို့ format ချထားသော string ရေးသွင်းခြင်း
php<?php
$file = fopen('output.txt', 'w');
$values = [10, 20.5, 'test'];
vfprintf($file, "Number: %d, Float: %.2f, String: %s", $values);
fclose($file);
?>
output.txt file ၏ content
php'Number: 10, Float: 20.50, String: test'
ဥပမာ
မတူညီသော specifiers များအသုံးပြုခြင်း
php<?php
$res = fopen('php://output', 'w');
$data = [15, 12.3456, 'ABCDE'];
vfprintf($res, "Hex: %x, Scientific: %.2e, Padding: '%5s'", $data);
fclose($res);
?>
Output ၏ရလဒ်
php'Hex: f, Scientific: 1.23e+1, Padding: \' ABCDE\''