note 38967 modified in function.gzfile by didou
| From: | didou@php.net | Date: | Fri, 14 Jan 2005 01:25:41 +0000 |
| Subject: | note 38967 modified in function.gzfile by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-83234@lists.php.net to get a copy of this message | ||
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;
}
?>
--was--
This is a port of what I've posted at http://www.php.net/file_get_contents
It 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
if (!function_exists('gzfile_get_contents')) {
function gzfile_get_contents($filename, $use_include_path = 0) {
$file = @gzopen($filename, 'rb', $use_include_path);
if ($file) {
$data = ''; // just to be safe. Dunno, if this is really needed
while (!gzeof($file)) $data .= gzread($file, 1024);
gzclose($file);
}
return $data;
}
}
?>
PS: if (!function_exists('gzfile_get_contents')) {
[...]
}
isn't really needed, but just in case.
http://php.net/manual/en/function.gzfile.php