本文介绍了写入MySQL时保留TextArea中的行中断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用textarea让用户输入评论。但是,如果用户输入新行,则新行在输出时不显示。是否有任何方法可以让换行符停留。



任何想法如何保留换行符?

解决方案

这个解决方案有两个:


  1. PHP函数:



    例如

      echo nl2br(This \r\ nis\\\
    \ra\\\
    string\r);

    //会输出
    这个< br />
    是< br />
    a< br />
    字符串< br />


  2. 将输入封装在< pre>< / pre> ; 标签。



    请参阅:

  3. I'm using a textarea to enable users to input comments. However, if the users enters new lines, the new lines don't appear when they are outputted. Is there any way to make the line breaks stay.

    Any idea how do preserve the line breaks?

    解决方案

    Two solutions for this:

    1. PHP function nl2br():

      e.g.,

      echo nl2br("This\r\nis\n\ra\nstring\r");
      
      // will output
      This<br />
      is<br />
      a<br />
      string<br />
      

    2. Wrap the input in <pre></pre> tags.

      See: W3C Wiki - HTML/Elements/pre

    这篇关于写入MySQL时保留TextArea中的行中断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 20:29