PHP 8.6.0 Beta 1 is available for testing

gzfile

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

gzfileСчитывает весь gz-файл в массив

Описание

function gzfile(string $filename, bool $use_include_path = false ): array |false

Аналогична readgzfile() , за исключением того, что она возвращает файл в массиве.

Список параметров

filename

Имя файла.

use_include_path
Если установлено значение true , то также выполняется поиск файлов в include_path.

Возвращаемые значения

Массив строк файла, в каждом элементе массива находится одна строка, пустые строки включаются, а переносы строк по-прежнему добавляются или false , если возникла ошибка.

Список изменений

Версия Описание
8.5.0 Тип параметра use_include_path теперь – логическое значение (bool ). Ранее он был целым числом (int ).

Примеры

Пример #1 Пример использования gzfile()

<?php
$lines = gzfile('somefile.gz');
foreach ($lines as $line) {
 echo $line;
}
?>

Смотрите также

  • readgzfile() - Выводит содержимое gz-файла
  • gzopen() - Открыть gz-файл

Нашли ошибку?

ИнструкцияИсправлениеСообщение об ошибке
+Добавить

Примечания пользователей 4 notes

up
4
nb_nonospamm_ at wtal dot de
20 years ago
In PHP4.4.1 I noticed that gzfile only reads up to 8190 bytes per line. I had a 20K SQL query that was cut into 3 parts - and wondered why the SQL server complained. 
Reading an uncompressed file with the file() command works as expected.
up
2
jani at php dot net
17 years ago
This function is not binary safe. (intentionally, or not, that's the question :)
up
1
The Jedi
21 years ago
A quicker way to load a gziped file in a string :
<?php
function gzfile_get_contents($filename, $use_include_path = 0)
{
 //File does not exist
 if( !@file_exists($filename) )
 { return false; }
 
 //Read and imploding the array to produce a one line string
 $data = gzfile($filename, $use_include_path);
 $data = implode($data);
 return $data;
}
?>
up
0
webmaster at ragnarokonline dot de
22 years ago
This works similar to gzfile() but it returns the file in a string instead of an array and doesn't write it to stdout compared to readgzfile.
Note: unlike the usual file-functions filesize won't work here, since the length-parameter of gzread refers to the uncompressed length, while filesize returns the size of the compressed file.
<?php
function gzfile_get_contents($filename, $use_include_path = 0) {
 $file = @gzopen($filename, 'rb', $use_include_path);
 if ($file) {
 $data = '';
 while (!gzeof($file)) {
 $data .= gzread($file, 1024);
 }
 gzclose($file);
 }
 return $data;
}
?>
+Добавить

AltStyle によって変換されたページ (->オリジナル) /