dsizd368332 2018-01-20 20:06
浏览 197

如何从具有自动换行符的textarea插入

I want to create a post system on my site.

The source is an HTML textarea value, which is inserted in a MySQL database and displayed like this:

<div align='center' style='background-color: #FFFFFF;text-align:left;width: 500px;padding: 10px;border-top: 5px solid #F45144;'>
<center><h1 style='color:#F45144;margin-top: -10;'>$Title</h1></center>
<p>
$Post
</div>
<br>
<style>br{line-height: 600%;}</style>

But The text isn't formatted correctly. (The "$Title" and "$Post" are 2 variables from database)

Look at the images: When I insert a post like this: enter image description here

I get this: enter image description here

When I insert a post like: enter image description here

The results are like: enter image description here

I want to insert like in img1 and get a result like in img4. (without the need to insert a <br>)

  • 写回答

1条回答 默认 最新

  • dtdt0454 2018-01-20 20:08
    关注

    Because you need to convert the text's newlines to the <br /> tag, you can achieve this by using the nl2br() function:

    echo nl2br($text);
    
    评论

    报告相同问题?

    悬赏问题

    • ¥15 我不明白为什么c#微软的官方api浏览器为什么不支持函数说明的检索,有支持检索函数说明的工具吗?
    • ¥15 ORBSLAM2框架跑ICL-NUIM数据集
    • ¥15 在我想检测ros是否成功安装时输入roscore出现以下
    • ¥30 老板让我做一个公司的投屏,实时显示日期,时间,安全生产的持续天数,完全没头绪啊
    • ¥15 Google Chrome 所有页面崩溃,三种解决方案都没有解决,我崩溃了
    • ¥20 使用uni-app发起网络请求,获取重定向302返回的cookie
    • ¥20 手机外部浏览器拉起微信小程序支付 (相关搜索:微信小程序)
    • ¥20 怎样通过一个网址找到其他同样模版的网址
    • ¥30 XIAO esp32c3 读取FDC2214的数据
    • ¥15 在工控机(Ubuntu系统)上外接USB蓝牙硬件进行蓝牙通信