在HTML中显示mysql换行符 [英] display mysql newline in HTML
本文介绍了在HTML中显示mysql换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们的mysql数据库中的某些字段似乎包含换行符,因此如果我对它们进行SELECT操作,则会针对单个SQL调用返回如下内容:
Certain fields in our mysql db appear to contain newline characters so that if I SELECT on them something like the following will be returned for a single SQL call:
Life to be sure is nothing much to lose
But young men think it is and we were young
如果我想在网页上显示此字段时保留换行符,是编写脚本来替换'\\\
\r'的标准解决方案HTML标记还是有更好的方法?
If I want to preserve the line breaks when displaying this field on a webpage, is the standard solution to write a script to replace '\n\r' with a br HTML tag or is there a better way?
谢谢!
Thanks!
推荐答案
<
nl2br()
加入< br />
为每个 \\\
。不要忘记首先逃避内容,以防止XSS攻击。见下:
nl2br()
adds in <br />
for every \n
. Don't forget to escape the content first, to prevent XSS attacks. See below:
<?php echo nl2br(htmlspecialchars($content)); ?>
这篇关于在HTML中显示mysql换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文