note 97011 deleted from function.gzfile by danbrown
| From: | danbrown@php.net | Date: | Sun, 28 Mar 2010 14:08:31 +0000 |
| Subject: | note 97011 deleted from function.gzfile by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-167460@lists.php.net to get a copy of this message | ||
Note Submitter: allan kelly AT gmail DOT com
----
<?php
##################################
# function file_as_array( $fname )
# open gz or plaintext files
function file_as_array( $fname )
{
##################################################
# load file - try .gz first because it's preferred
$a_entries = array();
if( preg_match( '/\.gz$/', $fname ) )
{
$gzfname = $fname;
}
else
{
$gzfname = $fname.".gz";
}
if( file_exists( $gzfname ) )
{
# Try for a .gz file
$a_entries = gzfile( $gzfname );
# gzfile has no FILE_IGNORE_NEW_LINES, so trim to remove newlines.
for( $i=0; $i<sizeof($a_entries); $i++ )
{
$a_entries[$i] = trim($a_entries[$i]);
}
}
else if( file_exists( $fname ) )
{
$a_entries = file( $fname, FILE_IGNORE_NEW_LINES );
}
return $a_entries;
} # END function file_as_array( $fname )
?>