如何在 Ruby 中编码/解码 HTML 实体? [英] How do I encode/decode HTML entities in Ruby?
本文介绍了如何在 Ruby 中编码/解码 HTML 实体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试解码一些 HTML 实体,例如 '<'
变成 '<'
.
我有一个旧 gem (html_helpers),但它似乎已被废弃两次.>
有什么推荐的吗?我需要在模型中使用它.
解决方案
HTMLEntities 可以做到:
: jmglov@laurana;sudo gem 安装 htmlentities成功安装 htmlentities-4.2.4: jmglov@laurana;irbirb(主):001:0>需要'htmlentities'=>[]irb(main):002:0>HTMLEntities.new.decode "&ieexcl;我'非常 对字符引用感到恼火!"=>¡我对角色参考非常恼火!"
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屋!
查看全文