Reputation: 175
I want to save the contents in the file in order.dat
and now
I'm using this PHP script:
<?php
$a_str = array(
"orderid"=>"175",
"txnid"=>"RC456456456",
"date"=>"54156456465",
"amount"=>"109$"
);
$file = 'order.txt';
$contents = implode(PHP_EOL, $a_str);
//$contents = $orderid.'|'.$txnid.'|'.$date.'|'.$amount;
$contents .= PHP_EOL . PHP_EOL;
file_put_contents($file, $contents);
print("|$contents|");
?>
How it is possible to save the data in order.dat
file in this format?
175|RC456456456|54156456465|109$|
Upvotes: 0
Views: 2498
Reputation: 4763
The second parameter should be the data: http://php.net/manual/en/function.file-put-contents.php
e.g.
$data = $orderid.'|'.$txnid.'|'.$date.'|'.$amount;
file_put_contents($file, $data, FILE_APPEND | LOCK_EX);
It would probably be better to store the line data in an array and then implode it around the |
character.
Upvotes: 1