PHP fopen() İşlevi
❮ PHP Dosya Sistemi ReferansıÖrnek
Dosyayı açın, satırları okuyun - EOF'ye ulaşılana kadar:
<?php
$file = fopen("test.txt", "r");
//Output lines until EOF is reached
while(! feof($file)) {
$line = fgets($file);
echo $line. "<br>";
}
fclose($file);
?>
Tanım ve Kullanım
fopen() işlevi bir dosya veya URL açar.
Not: Bir metin dosyasına yazarken, doğru satır sonu karakterini kullandığınızdan emin olun! Unix sistemleri \n'yi, Windows sistemleri \r\n'yi ve Macintosh sistemleri \r'yi satır bitiş karakteri olarak kullanır. Windows, dosyayla çalışırken \n'yi \r\n'ye çevirecek bir çeviri bayrağı ('t') sunar. İkili modu zorlamak için 'b'yi de kullanabilirsiniz. Bu bayrakları kullanmak için, mod parametresinin son karakteri olarak 'b' veya 't' belirtin.
Sözdizimi
fopen(filename, mode, include_path, context)
Parametre Değerleri
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 |
Teknik detaylar
Geri dönüş değeri: | Başarı durumunda bir dosya işaretçisi kaynağı, YANLIŞ ve başarısızlık durumunda bir hata. İşlev adının önüne bir "@" ekleyerek hatayı gizleyebilirsiniz. |
---|---|
PHP Sürümü: | 4.3+ |
PHP Değişiklik Günlüğü: | PHP 7.1: "e" seçeneği eklendi PHP 5.2: "c" ve "c+" seçenekleri eklendi |
❮ PHP Dosya Sistemi Referansı