doulan4371 2016-03-31 11:30
浏览 39

使用编辑选项时,nl2br()会创建一个额外的新行

I am using textarea to save content in mySQL DB and using nl2br to preserve line breaks used by user.

PHP method of using nl2br

$description = safe_var($_POST['description']);
$text = preg_replace('#[
]+#', "
", $description);
$description_html = nl2br($text);

Now, when i am using edit option of update the description then there is a new <br/> added everytime i press update button.

It means that if first time my content looks like as below

Line 1
-----one space
Line 2
----- One space
Line 3

And then if i update this content with some words then i get output like as below and this is not expected

Line 1
-----one space
-----one space
Line 2
----- One space
-----one space
Line 3
-----one space
Line 4

Is there any way to prevent new lines to already added spaces until unless user gives a space.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?
    • ¥15 matlab(相关搜索:紧聚焦)
    • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
    • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
    • ¥50 需求一个up主付费课程