လက်ရှိတည်နေရာ: ပင်မစာမျက်နှာ> နောက်ဆုံးရဆောင်းပါးများစာရင်း> Multiple Multiple အမျိုးအစားများကို output format လုပ်ထားသည့်အကြောင်းအရာများကို output format လုပ်ထားသောအကြောင်းအရာများကိုအသုံးပြုပါ

Multiple Multiple အမျိုးအစားများကို output format လုပ်ထားသည့်အကြောင်းအရာများကို output format လုပ်ထားသောအကြောင်းအရာများကိုအသုံးပြုပါ

gitbox 2025-05-29

VFPrintpf () ဆိုတာဘာလဲ။

VFPrintprintf () သည် PHP မှ format ချထားသောကြိုးများကိုသတ်မှတ်ထားသောဖိုင်စီးဆင်းမှုကိုရေးရန်စီစဉ်ထားသည်။ Finprintf () , vfrintf () မတူဘဲ parameter သည်စာရင်းတစ်ခုရရှိသည်။ ဒေတာအမျိုးမျိုးကိုပြောင်းလဲခြင်းနှင့်ပြုပြင်ခြင်းကိုပြောင်းလဲခြင်းနှင့်ပြုပြင်ခြင်းသည်ပိုမိုပြောင်းလွယ်ပြင်လွယ်စေသည်။

function ကိုအဓိပ္ပါယ်:

 int vfprintf ( resource $handle , string $format , array $args )
  • $ လက်ကိုင် - FOPEN () ဖြင့်ပြန်လာသောဖိုင်ညှိုးနွယ်အရင်းအမြစ်များ။

  • $ format : format string ကို။

  • $ args : formatted string အတွက်ဖြည့်စွက်ခံရဖို့ဒေတာများ၏ခင်းကျင်း။


formating strings မှထောက်ပံ့သောဒေတာအမျိုးအစားများ

vfrintprintf () တွင်ကျွန်ုပ်တို့သည်အမျိုးမျိုးသော output အမျိုးအစားများကိုထောက်ပံ့ရန် format identifiers များကိုသုံးနိုင်သည်။ ဘုံများတွင်:

  • % s : string ကို

  • % d : ကိန်း (ဒ decimal မ)

  • % f : floating အမှတ်နံပါတ်

  • % x : hexadecimal (စာလုံးအသေး)

  • % x : hexadecimal (caps)

  • % B : binary

  • % C : ASCII ဇာတ်ကောင်

ပိုမိုရှုပ်ထွေးသောထုတ်လုပ်မှုလိုအပ်ချက်များကိုဖြည့်စွက်ရန် (pastiscise, padding စသည်တို့) (pastiscing padding စသည်တို့) နှင့်အတူဤသတ်မှတ်ချက်များကိုပြုပြင်မွမ်းမံနိုင်သည်။


လက်တွေ့ကျသောဥပမာများ

ဥပမာ 1: ကြိုးနှင့်ကိန်းများကိုရေးပါ

 <?php
$fp = fopen("log.txt", "a");
$name = "Alice";
$age = 30;
vfprintf($fp, "Name: %s, Age: %d\n", array($name, $age));
fclose($fp);
?>

ဤကုဒ်သည်အောက်ပါအတိုင်း log.txt ဖိုင်ကိုရေးသည်။

 Name: Alice, Age: 30

ဥပမာ 2: floating point နံပါတ်ကိုရေးပြီးဒ decimal မကိန်းနှစ်ခုကိုသိမ်းထားပါ

 <?php
$fp = fopen("log.txt", "a");
$product = "Coffee";
$price = 19.456;
vfprintf($fp, "Product: %s, Price: \$%.2f\n", array($product, $price));
fclose($fp);
?>

ထုတ်လုပ်မှု -

 Product: Coffee, Price: $19.46

% .2F ဒီမှာဒီနေရာမှာဒ decimal မထားတဲ့နေရာနှစ်ခုကိုထိန်းသိမ်းထားတယ်။


ဥပမာ 3: URLs များကို dynamically ထုတ်ယူခြင်းနှင့်ဖိုင်များရေးရန်

 <?php
$fp = fopen("links.txt", "a");
$endpoint = "api/data";
$id = 42;
$url = "https://gitbox.net/%s?id=%d";
vfprintf($fp, $url."\n", array($endpoint, $id));
fclose($fp);
?>

ဖိုင်ကိုရေးထားသည့်အကြောင်းအရာများမှာ -

 https://gitbox.net/api/data?id=42

ဥပမာ 4: ရောနှောထားသောအမျိုးအစားရေးသားခြင်းမှတ်တမ်း

 <?php
$fp = fopen("debug.log", "a");
$time = date("Y-m-d H:i:s");
$userId = 101;
$success = true;
$ip = "192.168.1.10";
vfprintf($fp, "[%s] User ID: %d, Success: %s, IP: %s\n", array(
    $time, $userId, $success ? "true" : "false", $ip
));
fclose($fp);
?>

output ကိုဆင်တူသည် -

 [2025-05-29 15:30:00] User ID: 101, Success: true, IP: 192.168.1.10

သိကောင်းစရာများနှင့်ကြိုတင်ကာကွယ်မှုများ

  1. Security - သုံးစွဲသူထည့်သွင်းမှုများကို formating strings တိုက်ခိုက်မှုများကိုကာကွယ်ရန်,

  2. Array ၏အမိန့်သည်တိကျမှန်ကန်ရမည် - Parameter Array သည် format string တစ်ခုနှင့်ကိုက်ညီရမည်, အမိန့်သည်မမှားနိုင်ပါ။

  3. ဖိုင်ခွင့်ပြုချက် - ရေးသားထားသောဖိုင် သည် ခွင့်ပြုချက်ကိုရေးပါ

  4. ဘာသာစကားမျိုးစုံလိုက်လျောညီထွေဖြစ်အောင် - output ကို format လုပ်သည့်အခါ၎င်းကို Sprintf () နှင့် အရွယ်အစားနှင့်ဗျာဒနာများ ဖြင့်ကြိုတင်လုပ်ဆောင်နိုင်သည်။