如何用<br/>替换CR+LF? [英] How to replace CR+LF with <br />?
问题描述
例如:
用户提交带有 <textarea name="mytext" cols="35" rows="2"></textarea>
的表单并按下 ENTER 里面.如何将 CR-LF 替换为 <br/>
?
A user submits a form with a <textarea name="mytext" cols="35" rows="2"></textarea>
and presses ENTER within it. How would I replace the CR-LF with a <br />
?
推荐答案
CF为此提供了一个名为ParagraphFormat()的函数:
CF has a function for this called ParagraphFormat():
<cfset form.userText = paragraphFormat(form.usertext)/>
来自帮助文档 -
替换字符串中的字符:
- 带空格的单个换行符(CR/LF 序列)
- 带有 HTML 段落标签的双换行符 (
<p>
)
它可能比你想要的更多,因为它还查找双换行符并添加 <p>
和 </p>代码>标签.
It may do more than you want in that it also looks for double line breaks and adds <p>
and </p>
tags.
Ben 还有一个增强版本(UDF),称为paragraph2,可以轻松修改以获得您想要的确切效果.这是链接:
Ben also has an enhanced version (a UDF) called paragraph2 that would be easy to modify to get the exact affect you want. Here's the link:
http://www.cflib.org/udf/ParagraphFormat2
这篇关于如何用<br/>替换CR+LF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!