如何让该 HTML 显示格式化且不带标签?
我创建了一个博客(用于编码练习)。我使用富文本编辑器(ckeditor)并将帖子保存到数据库中。当我将帖子拉出以在 Label.Text 中显示时,它会显示所有 HTML 标记:
<p><strong>there was</strong> once a fox that lived</p>
<p> in the<span style="color: #ff0000"> woods</span></p>
如何以正确的格式(段落、颜色等)显示帖子,但没有 HTML 标记?
I created a blog (for coding practice). I use a Rich Text Editor (ckeditor) and save the post to a database. When I pull the post out to display in a Label.Text, it shows all the HTML tags:
<p><strong>there was</strong> once a fox that lived</p>
<p> in the<span style="color: #ff0000"> woods</span></p>
How do I get the post to display, with the proper formatting (paragraph, color, etc.), but without the HTML tags?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
仅供参考:文字产生的结果与标签相同......但我得到了答案,这有效:
FYI: The literal produced the same result as the Label ... but I got my answer, this works:
HTML 是格式,因此要让文本显示您想要的方式,您需要将文本作为 HTML 插入到页面中,而不是将文本插入到标签中.Text - 将其视为纯文本并显示所有标记。
因此,不要使用 Literal: 创建标签,而是使用 Literal:
那么在页面加载中:
字符串:
theText
将是从数据库读取的。如果您的字符串已被编码,您将必须调用
Server.HtmlDecode
以确保任何<
和>
代码都已转换返回到<
和>
。来源
Well the HTML is the formatting, so to get the text to display how you want you need to insert the text as HTML into your page rather than inserting the text into the Label.Text - which will treat is as plain text and display all the markup.
So rather than create a Label use a Literal:
Then in your page load:
theText
will be the string:as read from your database.
If your string has been Encoded you will have to call
Server.HtmlDecode
on it to make sure that any<
and>
codes are converted back to<
and>
.Source
我不明白。
您的意思是,当您检查该帖子时,您会得到类似以下内容:
将其保存为 .html 格式可能是个好主意,因为 RTF 从来就不是为互联网设计的。
听起来您一开始就不需要使用数据库。 XML 更适合此类任务。
I didn't understand.
Do you mean, when you check the post, you get something like:
It's probably a good idea to save it in .html format, since RTFs were never meant for the internet.
It also sounds like you don't need to use a database in the first place. XML is better for that kind of task.