drpjdfj618393 2015-02-01 15:09
浏览 155

在php Fwrite输出中添加换行符

Basically, I was trying to find a simple piece of code for a simple note taking thing in html, I want to type in an html input form, then that input be added on to a text file i found this,

<h1>Adding a text block to a text file:</h1>
<form action="index.php" method='post'>
<textarea name='textblock'></textarea>
<input type='submit' value='Add text'>
</form>

<?php

// Open the text file
$f = fopen("text.html", "a");

// Write text
fwrite($f, $_POST["textblock"]); 

// Close the text file
fclose($f);

// Open file for reading, and read the line
$f = fopen("text.html", "r");

// Read text
echo fgets($f); 
fclose($f);

?>

Which works, but needs line breaks at the end of the output, such as if i wrote "test" and then "test" again, it outputs as "testtest" obviously, but I want two line breaks between them, like

"Test

Test"

I also want to add another input called "Subject" which will be the subject of the note,I'm open to any suggestions, if this code is wrong, or over complicated, then feel free to shorten it or just give me a entirely new one.

Thanks for any help

Terry.

  • 写回答

3条回答 默认 最新

  • douhuike3199 2015-02-01 15:16
    关注

    in html you need to use <br /> . But your form probably writes in the database. use nl2br() for that:

    $htmltext = nl2br($f);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog