وظيفة 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 علامة ترجمة ('t') سيتم ترجمتها \ n إلى \ r \ n عند العمل مع الملف. يمكنك أيضًا استخدام "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 |
تفاصيل تقنية
قيمة الإرجاع: | مورد مؤشر ملف على النجاح و FALSE وخطأ عند الفشل. يمكنك إخفاء الخطأ عن طريق إضافة "@" أمام اسم الوظيفة. |
---|---|
إصدار PHP: | 4.3+ |
سجل التغيير في PHP: | PHP 7.1: تمت إضافة الخيار "e" PHP 5.2: تمت إضافة خياري "c" و "c +" |
❮ مرجع نظام ملفات PHP