从数据库中提取的文本显示为单行,格式不正确。

huangapple go评论55阅读模式
英文:

Text fetched from database is shown in single line not in correct formate

问题

I just created an aplication where is use php to save tasks and display them on dashboard
html form

it saving the data in correct formate
database table
but the problem is when I fetch that data and show it on dashboard it shows in a single line.
output on html page
i want that to appear normally with line breaks but i don't know why it's not adding line breaks while displaying data

I tried to find a way to solve this problem but no success

英文:

I just created an aplication where is use php to save tasks and display them on dashboard
html form

it saving the the data in correct formate
database table
but the problem is when I fectch that data and show it on dashboard it shows in a single line.
output on html page
i want that to apear normaly with line breaks but i don't know why it's not adding linebreaks while displaying data

I tried to find a way to sove this problem but no success

答案1

得分: 1

这似乎是将文本区域的内容直接插入到HTML中。
在表单的文本区域中,换行符按预期显示。但在表单之外,HTML不会格式化换行符(它会将所有空格折叠为一个空格)。
在HTML中有各种创建换行的方法,但在这里最简单的方法是用<br/>标记替换换行符。PHP甚至有一个函数nl2br()可以做到这一点。

值得注意的是,没有对用户输入进行清理就发布它,可能会导致跨站点脚本攻击(https://owasp.org/www-community/attacks/xss/),允许恶意用户在您的用户浏览器中运行任意JavaScript。

英文:

It looks like you're putting the contents of that textarea directly into html.
In textarea in forms, linebreaks are displayed as expected. But outside of forms, html does not format linebreaks (it collapses all whitespace in to a single space).
There are various ways to create linebreaks in html, but the simplest method here would be to replace the linebreak with the &lt;br/&gt; tag. php even has a function to do this nl2br()

It's worth noting, though, that posting user input without sanitizing it can result in Cross-site scripting attacks (https://owasp.org/www-community/attacks/xss/) that allow malicious users to run arbitrary javascript in your users' browsers.

huangapple
  • 本文由 发表于 2023年4月4日 04:39:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/75923603.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定