gpt4 book ai didi

ruby-on-rails - 如何去除 HTML 标签,包括没有 ' 和东西的转义图像标签?

转载 作者:行者123 更新时间:2023-12-04 09:31:58 28 4
gpt4 key购买 nike

我需要从我的内容中删除所有 html 元素。内容示例:

"<p><img alt=\"\" src=\"/ckeditor_assets/pictures/1/content_twitter-sink.jpg\" style=\"width: 570px; height: 399px;\" /></p>\r\n\r\n<h3 style=\"font-size: 1.38462em; margin: 1em 0px 0px; font-weight: 600; line-height: 1.2; font-family: freight-sans-pro, sans-serif; -webkit-font-smoothing: antialiased; text-rendering: optimizelegibility; color: rgb(46, 46, 46);\">Soraya Calavassy, communications manager at the Award in Australia,&nbsp;shares her organisation&#39;s experience&nbsp;piloting our new global visual identity.</h3>\r\n\r\n<p style=\"margin: 0.5em 0px 0px; text-rendering: optimizelegibility; font-size: 1.30769em; line-height: 1.3; color: rgb(78, 78, 78); font-family: freight-sans-pro, sans-serif;\">&quot;While Australia has a very strong brand locally, there are some great benefits for incorporating"

显示帖子时,我使用 raw ,它确实给了我需要的输出。但我需要生成一个摘录。为此,我需要去除所有 HTML 标签,甚至删除图像。但是当我使用 sanitizer 它不会删除图像。如果我使用 strip_tags ,它将删除图像,但会添加 &#39;对于撇号, &nbsp;用于空间等。那么,如何在没有图像且没有 &nbsp; 的情况下获得干净的摘录东西?

最佳答案

试试 strip_tags(text).html_safe

关于ruby-on-rails - 如何去除 HTML 标签,包括没有 ' 和东西的转义图像标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14680326/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com