Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 文件\u放置\u内容()不工作_Php - Fatal编程技术网

Php 文件\u放置\u内容()不工作

Php 文件\u放置\u内容()不工作,php,Php,我想以order.dat和now格式保存文件中的内容,我正在使用以下PHP脚本: <?php $a_str = array( "orderid"=>"175", "txnid"=>"RC456456456", "date"=>"54156456465", "amount"=>"109$" ); $file = 'order.txt'; $contents = implode(PHP_EOL, $a_str); //$contents =

我想以
order.dat
now
格式保存文件中的内容,我正在使用以下PHP脚本:

<?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|");
?>

第二个参数应为数据:

e、 g

最好将行数据存储在数组中,然后围绕
字符进行内爆

175|RC456456456|54156456465|109$|
$data = $orderid.'|'.$txnid.'|'.$date.'|'.$amount;
file_put_contents($file, $data, FILE_APPEND | LOCK_EX);