如何在此PHP脚本的末尾添加文本

时间:2016-10-03 23:16:13

标签: php

这是正常的脚本。它将数据保存到文件中。

       <?php
if (isset($_GET['field'])) {
$file = 'data.txt';
// Open the file to get existing content
$current = file_get_contents($file);

// Append a new line to the file
$current .= "\n".$_GET['field'];

// Write the contents back to the file
file_put_contents($file, $current);
}
?>

但是我希望它在发送的内容中添加(由用户添加)。我试过这个:

     <?php
if (isset($_GET['field'])) {
$file = 'data.txt';
// Open the file to get existing content
$current = file_get_contents($file);

// Append a new line to the file
$current .= "\n".$_GET['field'] + "(added by a user)";

// Write the contents back to the file
file_put_contents($file, $current);
}
?>

但它不起作用。我该怎么做?

0 个答案:

没有答案