PHP.写入文件

ash*_*him 0 php

我正在学习php.我想写一个字符串到文件,但没有任何反应.我该怎么调试呢?我有python的经验.在那里我可以使用终端尝试小代码片段,但我不知道如何在PHP中检查代码.

$myFile = "testFile.txt";
$fh = fopen($myFile, 'w');
$stringData = "Bobby Bopper\n";
$myvar = fwrite($fh, $stringData);
$stringData = "Tracy Tanner\n";
fwrite($fh, $stringData);
fclose($fh);
Run Code Online (Sandbox Code Playgroud)

Nie*_*sol 5

除非你真的需要使用文件处理程序,否则只需执行以下操作:

$myFile = "testFile.txt";
$stringData = "Bobby Bopper\nTracy Tanner\n";
file_put_contents($myFile,$stringData);
Run Code Online (Sandbox Code Playgroud)