PHP Snippets
get_ff
Information
(PHP Version >= 4.3.0)Functions used in this snippet: file_exists, unserialize, file_get_contents, is_array.
Description
array get_ff( str file)
Reads file contents and unserializes them to form a flat-file array. If the file cannot be read, or the contents of the file is not serialized, an empty array is returned.
Snippet
<?php
function get_ff($file){
if(file_exists($file)){
$array = @unserialize( file_get_contents( $file ) );
$array = is_array($array) ? $array : array();
return $array;
}
return array();
}
?>
Example
get_ff Can be used in the following way:
<?php
$array = get_ff('somefile.txt');
print_r($array); // outputs array stored in somefile.txt
$array = get_ff('non-existing-file.ext');
print_r($array); // outputs an empty array
?>
Updated on Jun 27th at 7 am.
0 Responses to get_ff