-1
请告诉我如何打开文件并将字符串放在每行的末尾php 这可能吗?如何打开文件并在每行的末尾放置php
谁能让我理解这段代码?
f = open('./ampo.txt', 'r+')
with open('./ampo.txt') as infile:
for line in infile:
f.insert(0, 'EDF ')
f.close
请告诉我如何打开文件并将字符串放在每行的末尾php 这可能吗?如何打开文件并在每行的末尾放置php
谁能让我理解这段代码?
f = open('./ampo.txt', 'r+')
with open('./ampo.txt') as infile:
for line in infile:
f.insert(0, 'EDF ')
f.close
为了追加到每行文件,你将不得不阅读文件,然后覆盖它。我实际上建议写入不同的文件,如果您选择这样做,只需在fopen调用中更改文件名。
$lines = file("./amp.txt");
$fp = fopen("./amp.txt", "w");
foreach($lines as $line) {
fwrite($fp, substr($line,0,-1) . "EDF" . substr($line,-1));
}
fclose($fp);
这可能是你想要什么
$myFile = "testFile.txt"; // The file
$fh = fopen($myFile, 'a') or die("can't open file"); // Open it
$stringData = "New Stuff 1\n"; // Your data
fwrite($fh, $stringData); // Write to file
$stringData = "New Stuff 2\n"; // Your data
fwrite($fh, $stringData); // Write again
fclose($fh); // Close it
的A(追加)中的fopen,会确保获得附加到文件
甚至不是远程PHP –
关于如何使用'“A +”',而不是'“R +”' –
看起来像Python来我... –