本文介绍了如何HTML编码/转义字符串?有内置吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个不可信的字符串,我想在HTML页面中显示为文本。我需要作为HTML实体将字符'<
'和'&
'。
I have an untrusted string that I want to show as text in an HTML page. I need to escape the chars '<
' and '&
' as HTML entities. The less fuss the better.
我正在使用UTF8,不需要其他实体用于重音字母。
I'm using UTF8 and don't need other entities for accented letters.
在Ruby或Rails中有内置函数,还是应该自己滚动?
Is there a built-in function in Ruby or Rails, or should I roll my own?
推荐答案
h
帮助方法:
<%=h "<p> will be preserved" %>
这篇关于如何HTML编码/转义字符串?有内置吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!