将输入数据保存在php文件中(无数据库)
是否可以在不使用任何数据库的情况下将输入数据保存在将输入数据保存在php文件中(无数据库),php,html,Php,Html,是否可以在不使用任何数据库的情况下将输入数据保存在php文件中 比如: echo " inputted text.. "; 或 使用fwrite,非常简单: <?php $fp = fopen('myfile.txt', 'w'); fwrite($fp, 'this is my database without database :p '); fclose($fp); ?> 如果要使用表单,并将一些变量提取到文件中,可以使用: 您在Form.html中的表单 <form
php
文件中
比如:
echo " inputted text.. ";
或
使用fwrite,非常简单:
<?php
$fp = fopen('myfile.txt', 'w');
fwrite($fp, 'this is my database without database :p ');
fclose($fp);
?>
如果要使用表单,并将一些变量提取到文件中,可以使用: 您在Form.html中的表单
<form action="recipient.php" method="POST">
INPUT1: <input type="text" name="text1" id="input1"><br/>
INPUT2: <input type="text" name="text2" id="input2"><br/>
FILENAME: <input type="text" name="filename" id="filename">
<button type="submit">Send now</button>
</form>
输入1:
输入2:
文件名:
立即发送
您的PHP recipient.PHP-无任何验证检查:
<?php
$varA = "\$varA = ".$_POST['input1'].";"; // put your string into varible $varA
$varB = "\$varB = ".$_POST['input1'].";"; // put your string into varible $varA
$fileName = $_POST['filename']; // set a filename from form field
$text = $varA ." ". $varB; // add all together
$filepath = fopen('/var/www/html/'.$fileName.'.php', 'w+'); // set filepath and fopen to new PHP-file
fwrite($filepath, '<?php '. $text); // write text as PHP-file
fclose($filepath); // close file
?>
如果您还没有读到关于它们的信息,请查看。您可能还想调查一下。
但除此之外,我强烈建议您仔细研究一下-它可以节省您的时间,而且更安全。也许您想要
文件\u put\u contents()
?可能会复制Txt文件json文件cookies,我想没有其他方法可以:/and编辑php文件,而不是Txt(也不是所有文本…)您的意思是要使用另一个php文件编辑file.php?
<?php
$varA = "\$varA = ".$_POST['input1'].";"; // put your string into varible $varA
$varB = "\$varB = ".$_POST['input1'].";"; // put your string into varible $varA
$fileName = $_POST['filename']; // set a filename from form field
$text = $varA ." ". $varB; // add all together
$filepath = fopen('/var/www/html/'.$fileName.'.php', 'w+'); // set filepath and fopen to new PHP-file
fwrite($filepath, '<?php '. $text); // write text as PHP-file
fclose($filepath); // close file
?>