Javascript 在文本文件中存储变量的值
我创建了一个简单的机制来获取一个人的名字和姓氏(这当然是最基本的代码)。但是,我想将变量的值写入文本文件。我使用了一些php,但它似乎不起作用:Javascript 在文本文件中存储变量的值,javascript,php,html,variables,storage,Javascript,Php,Html,Variables,Storage,我创建了一个简单的机制来获取一个人的名字和姓氏(这当然是最基本的代码)。但是,我想将变量的值写入文本文件。我使用了一些php,但它似乎不起作用: 要通过php编写文件,可以使用函数 下面是一个简单的代码示例: // The file where to write $file = 'db.txt'; // The content $file_content = $your_variable; // Write the content file_put_contents($file, $file_
要通过php编写文件,可以使用函数
下面是一个简单的代码示例:
// The file where to write
$file = 'db.txt';
// The content
$file_content = $your_variable;
// Write the content
file_put_contents($file, $file_content);
您还可以将内容附加到文件:
// The file where to write
$file = 'db.txt';
// Old content
$file_content = file_get_contents($file);
// Old + new content
$file_content .= $your_variable;
// Write the content
file_put_contents($file, $file_content);
您还可以将以下内容标志附加到文件中:
// The file where to write
$file = 'db.txt';
// New content
$file_content = $your_variable;
// Write the content
file_put_contents($file, $file_content, FILE_APPEND | LOCK_EX);
// FILE_APPEND: used to append the new contents at the end of the file
// LOCK_EX : used to avoid another user to write on the same file at the same time
要通过php编写文件,可以使用函数 下面是一个简单的代码示例:
// The file where to write
$file = 'db.txt';
// The content
$file_content = $your_variable;
// Write the content
file_put_contents($file, $file_content);
您还可以将内容附加到文件:
// The file where to write
$file = 'db.txt';
// Old content
$file_content = file_get_contents($file);
// Old + new content
$file_content .= $your_variable;
// Write the content
file_put_contents($file, $file_content);
您还可以将以下内容标志附加到文件中:
// The file where to write
$file = 'db.txt';
// New content
$file_content = $your_variable;
// Write the content
file_put_contents($file, $file_content, FILE_APPEND | LOCK_EX);
// FILE_APPEND: used to append the new contents at the end of the file
// LOCK_EX : used to avoid another user to write on the same file at the same time
你是指Java还是JavaScript?JavaScript:-)@Khelwood你是指Java还是JavaScript?JavaScript:-)@Khelwood你是指Java还是JavaScript?JavaScript:-)@Khelwood是的,在我看来,文件内容()对于初学者来说更容易使用。是的,我认为文件内容()对于初学者来说更容易使用。是的,文件内容()在我看来,这对初学者来说更容易使用。