[英]How to save file txt using html and php
i try to save textarea in html to file ("C:\xampp\htdocs\test\1\one.txt")我尝试将 html 中的 textarea 保存到文件(“C:\xampp\htdocs\test\1\one.txt”)
so i figure out i must use php too.所以我想我也必须使用 php。
this php code, it work fine这个 php 代码,它工作正常
$fp = fopen('one.txt', 'w');
fwrite($fp, 'edit me please');
fclose($fp);
?>
so how can i use html textarea to edit php ' edit me please ' to any text i wanna to edit, plus that i wanna to enable multi line which save in one.txt if i need to.那么我如何使用 html textarea 来编辑 php '请编辑我'到我想编辑的任何文本,另外,如果我需要,我想启用多行保存在 one.txt 中。
my html code我的 html 代码
<!DOCTYPE html>
<html>
<head>
<title>Using innerHTML</title>
</head>
<body>
your one.txt write in textarea :
<br>
<textarea id="emp" rows = "20" cols = "90" name = "description"></textarea>
<br>
<p>
<input type="button" id="bt" value="Change Label Text" onclick="Onclicky()" />
</p>
</body>
<script language="javascript">
function Onclicky() {
/////function which will do work, idk?!////
}
</script>
</html>
Update #1 (try to add php inside html), but still not work no txt file data created.)更新#1(尝试在 html 中添加 php),但仍然无法工作,没有创建 txt 文件数据。)
<html>
<body>
<form action="" method="post">
<textarea name="text"></textarea>
<input type="submit" value="edit" />
</form>
<?php
if(isset($_POST["text"]){
$fp = fopen('one.txt', 'w');
if(fwrite($fp, $_POST["text"])){
echo "Edited";
}
fclose($fp);
}
?>
</body>
</html>
i'm still new, will be glade for your help:)..我还是新手,很高兴为您提供帮助:)..
You Need To know More About "Handle Form Using PHP".您需要了解有关“使用 PHP 处理表单”的更多信息。
html: html:
<form action="your_data.php" method="get">
Enter a Name:
<br>
<textarea id="emp" rows = "20" cols = "90" name = "name"></textarea>
<br>
<input type="submit">
</form>
</body>
</html>
your_data.php: your_data.php:
<html>
<body>
your data :
<?php
$fp = fopen('one.txt', 'w');
fwrite($fp, $_GET["name"]);
fclose($fp);
?>
</body>
</html>
Here is the most easiest way to do it.这是最简单的方法。
<form action="" method="post">
<textarea name="text"></textarea>
<input type="submit" value="edit" />
</form>
<?php
if(isset($_POST["text"]){
$fp = fopen('one.txt', 'w');
if(fwrite($fp, $_POST["text"])){
echo "Edited";
}
fclose($fp);
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.