php如何实现记事本

php如何实现记事本

小编给大家分享一下php如何实现记事本,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

php实现记事本的具体代码

记事本案例

要求:1)页面上有一个文本域(textarea元素),和一个发表按钮
           2)用户在文本域中输入内容后,点击发表按钮,会以当天的日期和时间创建一个记事本,并将用户输入的内容保存到记事本中

效果:

php如何实现记事本

代码:

<style>
 textarea{
 resize: none;
 border: 2px solid #000;
 outline: none;
 }
 input{
 margin-top: 15px;
 width: 80px;
 height: 30px;
 border: none;
 outline: none;
 color: #fff;
 background-color: orange;
 }
</style>
<form action="4.php" method="post">
 <textarea name="text" id="" cols="30" rows="10"></textarea>
 <div><input type="submit" name="btn" value="发表"></div>
 
</form>


<?php
// 方法一
$file=$_POST['text'];
$filename = date('Ymd',time()).'.txt';
$fh=fopen($filename,'a'); 
fwrite($fh,$file);
fclose($fh);


// 方法二
// file_put_contents('1.txt',$file);


?>

拓展知识点:

php如何实现记事本

以上是“php如何实现记事本”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注行业资讯频道!