drupal 7删除样式标签形式rss视图字段

时间:2017-12-28 09:18:01

标签: php drupal-7

我有两个视图,基本上他们做同样的事情(列出节点的内容)。但一个是在页面上显示内容而另一个是在rss文件上导出相同的内容。问题是一个名为“description”的字段是一个文本,用户可以放置一些样式,因此它可以包含css标签“”。尽管rss视图会在描述字段内容中导出“....”标记,但在第一个视图上显示样式绝对没问题。并且应该从rss文件中删除此样式标记。我试图使用管理界面去除html标签,它不起作用,我主题描述字段模板,并使用reg_replace删除样式标签,它也不起作用,所以我试图循环内容并删除样式标签。但Drupal输出一个错误“限制执行”,因为该字段有这么多的内容(我可以增加本地的执行时间,它的工作原理,但在生产时不推荐)。因为字段内容可以包含长文本项,还有另一种方法可以从rss视图中删除样式标记吗?

// views-view-field--VIEWNAME-feed--views-data-export-1--field-th-paragraphs.tpl.php

<?php
// get position of styling tag
$pos = strpos($output, 'text/css');
$endpos = strpos($output, '</style>');
// iterate at least one time to remove css
do
{
// check if description has css tag
if($pos > 0)
{
    // the closing tag of the css maybe cut off
    if($endpos > 0)
        $length = $endpos - $pos;
    else
        $length = $endpos - strlen($newoutput);
    // repeat process until removing all css tags
    $newoutput = substr_replace($newoutput, '', ($pos - 13), ($length 
    + 20));
    $pos = strpos($newoutput, 'text/css');
    $endpos = strpos($newoutput, '</style>');
}
else{
    print $output;
}
} 
while( $pos > 0);
print($output);
?>

1 个答案:

答案 0 :(得分:0)

打开视图,转到字段设置,在重写结果下,您有一个选项:剥离HTML标记