简体   繁体   中英

drupal 7 remove style tag form rss view field

i have two views, which basically they are doing the same thing (list the content of a node) .But one is to display the content on a page and the other is exporting the same content on rss file. The problem is one field named "description" is a text and user can put some styling, so it could contains css tag "". Its absolutely fine to display style on the first view, although the rss view will export the "...." tag among the description field content. and this style tag should be removed from the rss file. i have tried to use admin interface to strip the html tags and and it does not work, i have themed the description field template and remove style tag using reg_replace and it does not work also, so i have tried to loop through the content and remove style tag. But Drupal output an error "limit execution", because the field so much content(i can increase the execution time on local and it works, but on production its not recommended). because the field content can contain a long text items, is there an other way to remove style tag from the rss view ?

// 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);
?>

打开视图,转到字段设置,在“重写结果”下,您可以选择:剥离HTML标签

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM