PHP fopen() လုပ်ဆောင်ချက်
❮ PHP ဖိုင်စနစ် အကိုးအကားဥပမာ
ဖိုင်ကိုဖွင့်ပါ၊ EOF မရောက်မချင်း စာကြောင်းများကိုဖတ်ပါ။
<?php
$file = fopen("test.txt", "r");
//Output lines until EOF is reached
while(! feof($file)) {
$line = fgets($file);
echo $line. "<br>";
}
fclose($file);
?>
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
fopen() လုပ်ဆောင်ချက်သည် ဖိုင် သို့မဟုတ် URL ကို ဖွင့်ပေးသည်။
မှတ်ချက်- စာသားဖိုင်သို့ စာရေးသည့်အခါ မှန်ကန်သော စာကြောင်းအဆုံး စာလုံးကို သေချာစွာ အသုံးပြုပါ။ Unix စနစ်များသည် \n ကိုအသုံးပြုသည်၊ Windows စနစ်များသည် \r\n ကိုအသုံးပြုကြပြီး Macintosh စနစ်များသည် \r ကို မျဉ်းအဆုံးစာလုံးအဖြစ် အသုံးပြုသည်။ Windows သည် ဖိုင်နှင့်အလုပ်လုပ်သောအခါ \n သို့ \r\n ဘာသာပြန်မည့် ဘာသာပြန်အလံ ('t') ကို ပေးပါသည်။ binary မုဒ်ကို အတင်းအကြပ်လုပ်ရန် 'b' ကိုသုံးနိုင်သည်။ ဤအလံများကိုအသုံးပြုရန်၊ မုဒ်ပါရာမီတာ၏နောက်ဆုံးစာလုံးအဖြစ် 'b' သို့မဟုတ် 't' ကို သတ်မှတ်ပါ။
အထားအသို
fopen(filename, mode, include_path, context)
ကန့်သတ်တန်ဖိုးများ
Parameter | Description |
---|---|
filename | Required. Specifies the file or URL to open |
mode | Required. Specifies the type of access you require to the file/stream. Possible values:
|
include_path | Optional. Set this parameter to '1' if you want to search for the file in the include_path (in php.ini) as well |
context | Optional. Specifies the context of the file handle. Context is a set of options that can modify the behavior of a stream |
နည်းပညာဆိုင်ရာအသေးစိတ်
ပြန်ပို့တန်ဖိုး- | အောင်မြင်မှုဆိုင်ရာ ညွှန်ပြချက် အရင်းအမြစ်တစ်ခု၊ မှားယွင်းချက်နှင့် ကျရှုံးမှုဆိုင်ရာ အမှားတစ်ခု။ လုပ်ဆောင်ချက်အမည်၏ ရှေ့တွင် "@" ကို ထည့်ခြင်းဖြင့် အမှားကို ဖျောက်နိုင်သည်။ |
---|---|
PHP ဗားရှင်း- | 4.3+ |
PHP Changelog- | PHP 7.1- ထည့်ထားသော "e" ရွေးစရာ PHP 5.2- "c" နှင့် "c+" ရွေးစရာများကို ထည့်ထားသည် |
❮ PHP ဖိုင်စနစ် အကိုးအကား