CakeFest 2024: The Official CakePHP Conference

gzgets

(PHP 4, PHP 5, PHP 7, PHP 8)

gzgetsGzipli dosya tanıtıcısından bir satır döndürür

Açıklama

gzgets(resource $dt, ?int $uzunluk = null): string|false

Belirtilen dosya tanıtıcısında mevcut konumdan itibaren en fazla (sıkıştırılmamış) uzunluk - 1 bayt okur. Okuma işlemi uzunluk - 1 baytta, ilk satırsonu karakterinde veya dosya sonuna gelindiğinde (hangisi önce olursa) durur.

Bağımsız Değişkenler

dt

Gzipli dosya tanıtıcısı. gzopen() tarafından açılmış bir dosyayı gösteren geçerli bir tanıtıcı olmalıdır.

uzunluk

Okunacak verinin uzunluğu.

Dönen Değerler

Bir hata oluşursa false aksi takdirde sıkıştırılmamış dizgeyi döndürür.

Sürüm Bilgisi

Sürüm: Açıklama
8.0.0 uzunluk artık null olabiliyor; evvelce, 1024 öntanımlıydı.

Örnekler

Örnek 1 - gzgets() örneği

<?php
$dt
= gzopen('birdosya.gz', 'r');
while (!
gzeof($dt)) {
$tampon = gzgets($dt, 4096);
echo
$tampon;
}
gzclose($dt);
?>

Ayrıca Bakınız

  • gzopen() - Bir gzipli dosya açar
  • gzgetc() - Gzipli dosya göstericisindeki karakteri döndürür
  • gzwrite() - Bir dizgeyi bir gzipli dosyaya ikil kipte yazar

add a note

User Contributed Notes 3 notes

up
1
prismngp1 at yahoo dot com
21 years ago
<?
// this is simple code by VIJAY to unzip .gz file
$file = "/absolute/path/to/your/file" ;
$fp = fopen("$file", "w") ;
// file to be unzipped on your server
$filename = "filename.gz" ;
$zp = gzopen($filename, "r");

if ($zp)
{
while (!gzeof($zp))
{
$buff1 = gzgets ($zp, 4096) ;
fputs($fp, $buff1) ;
}
}
gzclose($zp) ;
fclose($fp) ;
?>
up
0
divinity76 at gmail dot com
4 years ago
PS when it encounters and breaks on a newline byte ("\n"), the newline byte itself is not included in the returned string.
up
0
Anonymous
18 years ago
For the above example by VIJAY, using gzgetc would be better, as I've encountered binary/text file incompatibilities (at least with PHP 4.0.4).
To Top