पीएचपी file_put_contents () समारोह
❮ पीएचपी फाइल सिस्टम संदर्भउदाहरण
फ़ाइल में डेटा लिखें:
<?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. |
टेक्निकल डिटेल
प्रतिलाभ की मात्रा: | सफलता पर फ़ाइल में लिखी गई बाइट्स की संख्या, विफलता पर FALSE |
---|---|
पीएचपी संस्करण: | 5.0+ |
बाइनरी सुरक्षित: | हां |
पीएचपी चेंजलॉग: | PHP 5.1 - LOCK_EX के लिए अतिरिक्त समर्थन और डेटा पैरामीटर में स्ट्रीम संसाधन पास करने की क्षमता |
❮ पीएचपी फाइल सिस्टम संदर्भ