這篇文章給大家分享的是用PHP實(shí)現(xiàn)記事本的相關(guān)內(nèi)容,具體的實(shí)現(xiàn)需求如下,小編覺得對(duì)大家學(xué)習(xí)PHP有一定的而幫助,因此分享給大家做個(gè)參考,文中示例代碼介紹的非常詳細(xì),感興趣的朋友接下來一起跟隨小編看看吧。
記事本案例
要求:1)頁面上有一個(gè)文本域(textarea元素),和一個(gè)發(fā)表按鈕
2)用戶在文本域中輸入內(nèi)容后,點(diǎn)擊發(fā)表按鈕,會(huì)以當(dāng)天的日期和時(shí)間創(chuàng)建一個(gè)記事本,并將用戶輸入的內(nèi)容保存到記事本中
效果:

代碼:
<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="發(fā)表"></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); ?>
拓展知識(shí)點(diǎn):
