arraystore.php

<?

#       arraystore.php - Copyright(c) 2005 by Mikkel C.M.Christensen
#
#       Stores and retrieves arrays of the following format from plaintextfiles:
#       $array =        array(  array ("",""),
#                               array ("",""),
#                               array ("",""));
#
#       The char "|" are used as seperator and can not be in the arrays
#       if present it will simply be removed.


function SaveArray($array,$file)
{
        $fh=fopen("test.arr","w");
        foreach ($array as $value)
        {
                $value=preg_replace(array("/\|/","/\n/"),array("","|n"),$value);
                fputs($fh, $value[0]."||".$value[1]."\n");
        }
        fclose($fh);
}

function LoadArray($file)
{
        $fh=fopen($file,"r");
        while ($dat=fgets($fh))
        {
                $line=explode("||",$dat);
                $line=preg_replace("/\|n/","\n",$line);
                $arr[]=array($line[0],$line[1]);
        }
        fclose($fh);
        return $arr;
}

?>

 

Dette indlæg blev udgivet i Knowledge Base, Linux, Old Base, Programmering. Bogmærk permalinket.

Skriv et svar