问题描述
我必须将字符编码为Html:
<到<
>到& gt;
'到&#39;
至& quot;
& to& amp;
我在PHP中寻找像这样的实用程序功能:
字符串htmlspecialchars(字符串inputText)
是否可以使用JSoup来编码这些字符?
(我发现在Spring框架中,我想用这个简单的函数来使用Spring框架。)
JSoup是一个解析HTML的库。 p>
我不认为你可以用它来把特殊字符编码成HTML。
最好的方法是编写你自己的方法,只需从Spring中获取这个方法,你就不需要了etup整个框架。参见。
I have to encode characters to Html:
< to <
> to >
' to '
" to "
& to &
I look for a utility function like htmlspecialchars in PHP:
String htmlspecialchars(String inputText)
Is it possible to use JSoup to encode these characters?
(I have found htmlEscape in the Spring framework, but I don't want to use the Spring framework just for this simple function.)
JSoup is a library to parse the HTML.
I dont think you can use it to encode special characters into HTML.
The best way to do it, is to write your own method. Simply you can grab this method from Spring and you dont need to setup whole framework. See source code.
这篇关于使用jsoup来编码Html字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!