如何在Ruby中编码/解码HTML实体?

如何在Ruby中编码/解码HTML实体?

我试图解码一些HTML实体,如'&amp;lt;'成为'<'

我有一个旧的宝石(html_helpers),但似乎已经放弃了两次。

有什么建议?我需要在模型中使用它。


慕慕森
浏览 698回答 3
3回答

慕码人8056858

HTMLEntities可以做到::&nbsp;jmglov@laurana;&nbsp;sudo&nbsp;gem&nbsp;install&nbsp;htmlentitiesSuccessfully&nbsp;installed&nbsp;htmlentities-4.2.4:&nbsp;jmglov@laurana;&nbsp;&nbsp;irb irb(main):001:0>&nbsp;require&nbsp;'htmlentities'=>&nbsp;[]irb(main):002:0>&nbsp;HTMLEntities.new.decode&nbsp;"&iexcl;I&#39;m&nbsp;highly&nbsp;annoyed&nbsp;with&nbsp;character&nbsp;references!"=>&nbsp;"¡I'm&nbsp;highly&nbsp;annoyed&nbsp;with&nbsp;character&nbsp;references!"
打开App,查看更多内容
随时随地看视频慕课网APP