Load and save a array dump


<?php
function load_array_dump($filename) {
    $fp = fopen($filename,"r");
    $content = fread($fp,filesize($filename));
    fclose($fp);

    eval('$array='.gzuncompress(stripslashes($content)).';');
    return($array);
}

function save_array_dump($filename, $array) {
    $dump = addslashes(gzcompress(var_export($array,true),9));
    $fp = fopen($filename, "wb+");
    fwrite($fp, $dump);
    fclose($fp);
}

$array = array(
            'associative' => array('a' => 'value a','b' => 'value b'),
            'numerical' => array('value 1','value 2','value 3')
            );
save_array_dump('test.txt', $array);

echo '<pre>';
print_r(load_array_dump('test.txt'));
echo '</pre>';
?>

thanks to : http://www.jonasjohn.de/snippets/php/load-and-save-a-array-dump.htm

Share on Facebook




About Pragnesh Karia

Pragnesh Karia, Open Source Enthusiast, Software Professional, Software Developer, Technical Lead ,Magento, Joomla ,Joomla LMS , Moodel LMS ,PHP ,Mysql, Ajax, Javascript, Jquery, Linux, Fan of Open Sources , Annet Technologies , SEO Analyst , Mootools