पीएचपी fopen () समारोह
❮ पीएचपी फाइल सिस्टम संदर्भउदाहरण
फ़ाइल खोलें, पंक्तियाँ पढ़ें - जब तक 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 खोलता है।
नोट: टेक्स्ट फ़ाइल में लिखते समय, सही लाइन-एंडिंग कैरेक्टर का उपयोग करना सुनिश्चित करें! यूनिक्स सिस्टम \n का उपयोग करते हैं, विंडोज सिस्टम \r\n का उपयोग करते हैं, और Macintosh सिस्टम \r को लाइन एंडिंग कैरेक्टर के रूप में उपयोग करते हैं। विंडोज़ एक अनुवाद ध्वज ('टी') प्रदान करता है जो फ़ाइल के साथ काम करते समय \n से \r\n में अनुवाद करेगा। आप बाइनरी मोड को बाध्य करने के लिए 'बी' का भी उपयोग कर सकते हैं। इन फ़्लैग्स का उपयोग करने के लिए, मोड पैरामीटर के अंतिम वर्ण के रूप में या तो 'बी' या 'टी' निर्दिष्ट करें।
वाक्य - विन्यास
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 |
टेक्निकल डिटेल
प्रतिलाभ की मात्रा: | सफलता पर फ़ाइल सूचक संसाधन, FALSE और विफलता पर त्रुटि। आप फ़ंक्शन नाम के सामने "@" जोड़कर त्रुटि छिपा सकते हैं। |
---|---|
पीएचपी संस्करण: | 4.3+ |
पीएचपी चेंजलॉग: | PHP 7.1: जोड़ा गया "e" विकल्प PHP 5.2: जोड़ा गया "c" और "c+" विकल्प |
❮ पीएचपी फाइल सिस्टम संदर्भ