英文:
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 <br/> 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论