如何删除 rss 中的引号

问题描述 投票:0回答:1

我的 RSS feed 中有这个,在 drupal 视图中:

<link>Prueba &quot;con comillas&quot;</link>

我尝试创建一个这样的模块:

function views_without_encoded_preprocess_views_view_views_rss(&$vars) {
  if (!empty($vars['rss_feed'])) {
    $vars['rss_feed'] = strtr($vars['rss_feed'], array(
      '&amp;#039;' => '&#039;',
      '&amp;quot;' => '&quot;',
      '&amp;lt;' => '&lt;',
      '&amp;gt;' => '&gt;',
      '&amp;amp;' => '&amp;',
      '&quot;gt' => '',
    ));
  }
}

但一切都不顺利。我继续看到这部分:

<link>Prueba &quot;con comillas&quot;</link>

仅用于报价。

php html drupal rss quotes
1个回答
3
投票

据我所知,您尝试使用 Views RSS。

有一个修复似乎有效,但仅在 Drupal 6 站点进行了测试。在 Drupal 7 中,有些事情发生了变化,但试试这个:

转到 views_rss/theme 并打开 theme.inc

复制整个'function template_preprocess_views_view_views_rss函数,并将其放入主题的template.php中。

将函数名称更改为:function yourthemename_precrocess_views_view_views_rss

然后在原始主题的第 200 行,或者在“// Add XML element(s) to the item array”的位置,在上面插入以下内容:

if (empty($rss_elements)) continue;
       // Insert here -- clean up special characters
       $rss_elements[0]['value'] = htmlspecialchars_decode(trim(strip_tags(decode_entities( $rss_elements[0]['value'])),"\n\t\r\v\0\x0B\xC2\xA0 "));
       $rss_elements[0]['value'] = htmlspecialchars($rss_elements[0]['value'], ENT_COMPAT);
       // end of cleaning
       // Add XML element(s) to the item array.
       $rss_item['value'] = array_merge($rss_item['value'], $rss_elements);
}

检查您的 RSS...您可能需要刷新缓存几次。

您可以尝试的另一件事是htmlspecialchars。在我看来,Views RSS 字段的输出可以使用它来强制对引号、撇号和与号进行编码。

希望有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.