i am trying to store data in a text file, something like an array into a text file using php instead of storing into mysql database.
for example here are the data to
These functions should do what you want :
function storeInTextFile($array,$path) {
if(file_exists($path)) {
$handle = fopen($path,'wb');
fwrite($handle, arrayToString($array));
fclose($handle);
}
}
function arrayToString($array) {
$string = '';
foreach($array as $key => $value) {
$string .= "{$key} => {$value}\n";
}
return $string;
}
function stringToArray($string) {
$explodedString = explode('\n',$string);
$returnArray = array();
foreach($explodedString as $arrayValue) {
list($key,$value) = explode(' => ',$arrayValue);
$returnArray[$key] = $value;
}
return $returnArray;
}