Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/417.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/227.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
Javascript 在文本文件中存储变量的值_Javascript_Php_Html_Variables_Storage - Fatal编程技术网

Javascript 在文本文件中存储变量的值

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,但它似乎不起作用:


要通过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是的,在我看来,文件内容()对于初学者来说更容易使用。是的,我认为文件内容()对于初学者来说更容易使用。是的,文件内容()在我看来,这对初学者来说更容易使用。