PHP file_put_contents() လုပ်ဆောင်ချက်
❮ PHP ဖိုင်စနစ် အကိုးအကားဥပမာ
ဒေတာကို ဖိုင်တစ်ခုသို့ ရေးပါ-
<?php
echo file_put_contents("test.txt","Hello World. Testing!");
?>
အထက်ဖော်ပြပါ ကုဒ်၏ အထွက်သည်-
21
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
file_put_contents() သည် ဖိုင်တစ်ခုသို့ အချက်အလက်များကို ရေးသားသည်။
ဤလုပ်ဆောင်ချက်သည် ဖိုင်တစ်ခုကိုဝင်ရောက်သည့်အခါ ဤစည်းမျဉ်းများကို လိုက်နာသည်-
- FILE_USE_INCLUDE_PATH ကို သတ်မှတ်ပါက၊ ဖိုင်အမည် မိတ္တူအတွက် ပါဝင်လမ်းကြောင်းကို စစ်ဆေးပါ။
- ဖိုင်မရှိလျှင် ဖန်တီးပါ။
- ဖိုင်ကိုဖွင့်ပါ။
- LOCK_EX သတ်မှတ်ပါက ဖိုင်ကို လော့ခ်ချပါ။
- FILE_APPEND ကို သတ်မှတ်ပါက၊ ဖိုင်၏အဆုံးသို့ ရွှေ့ပါ။ မဟုတ်ပါက ဖိုင်အကြောင်းအရာကို ရှင်းလင်းပါ။
- အချက်အလက်တွေကို ဖိုင်ထဲမှာ ရေးပါ။
- ဖိုင်ကိုပိတ်ပြီး သော့ခလောက်ကို လွှတ်လိုက်ပါ။
မှတ်ချက်- ဖိုင်၏ ရှိပြီးသား အကြောင်းအရာကို ဖျက်ခြင်းမှ ရှောင်ကြဉ်ရန် FILE_APPEND ကို အသုံးပြုပါ။
အထားအသို
file_put_contents(filename, data, mode, context)
ကန့်သတ်တန်ဖိုးများ
Parameter | Description |
---|---|
filename | Required. Specifies the path to the file to write to. If the file does not exist, this function will create one |
data | Required. The data to write to the file. Can be a string, array, or a data stream |
mode | Optional. Specifies how to open/write to the file. Possible values:
|
context | Optional. Specifies the context of the file handle. Context is a set of options that can modify the behavior of a stream. |
နည်းပညာဆိုင်ရာအသေးစိတ်
ပြန်ပို့တန်ဖိုး- | အောင်မြင်မှုတွင် ဖိုင်တွင်ရေးထားသော ဘိုက်အရေအတွက်၊ ရှုံးနိမ့်မှုအပေါ် မှားသည်။ |
---|---|
PHP ဗားရှင်း- | 5.0+ |
Binary Safe- | ဟုတ်ကဲ့ |
PHP Changelog- | PHP 5.1 - LOCK_EX အတွက် ပံ့ပိုးမှု ပေါင်းထည့်ထားပြီး ဒေတာပါရာမီတာသို့ stream အရင်းအမြစ်ကို ဖြတ်သန်းနိုင်မှု |
❮ PHP ဖိုင်စနစ် အကိုးအကား