How to HTML encode/escape a string? Is there a built-in?(如何对字符串进行 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.
I'm using UTF8 and don't need other entities for accented letters.
Is there a built-in function in Ruby or Rails, or should I roll my own?
The h
helper method:
这篇关于如何对字符串进行 HTML 编码/转义?有内置的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!