如何在Ruby中编码/解码HTML实体? [英] How do I encode/decode HTML entities in Ruby?
本文介绍了如何在Ruby中编码/解码HTML实体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图解码一些HTML实体,例如'& lt;'
变成'<'
我有一个老宝石( html_helpers ),但它似乎已被放弃两次。
任何建议?我将需要在模型中使用它。
HTMLEntities 可以做到这一点:
:jmglov @ laurana; sudo gem install htmlentities
成功安装htmlentities-4.2.4
:jmglov @ laurana; irb
irb(main):001:0>要求'htmlentities'
=> []
irb(main):002:0> HTMLEntities.new.decode& iexcl;我很高兴并且带有人物参考!
=> 我非常讨厌角色参考!
I am trying to decode some HTML entities, such as '&lt;'
becoming '<'
.
I have an old gem (html_helpers) but it seems to have been abandoned twice.
Any recommendations? I will need to use it in a model.
解决方案
HTMLEntities can do it:
: jmglov@laurana; sudo gem install htmlentities
Successfully installed htmlentities-4.2.4
: jmglov@laurana; irb
irb(main):001:0> require 'htmlentities'
=> []
irb(main):002:0> HTMLEntities.new.decode "¡I'm highly annoyed with character references!"
=> "¡I'm highly annoyed with character references!"
这篇关于如何在Ruby中编码/解码HTML实体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文