簡體   English   中英

drupal 7從rss視圖字段中刪除樣式標簽

[英]drupal 7 remove style tag form rss view field

我有兩個視圖,基本上它們在做同一件事(列出節點的內容)。但是一個視圖是在頁面上顯示內容,另一個視圖是在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);
?>

打開視圖,轉到字段設置,在“重寫結果”下,您可以選擇:剝離HTML標簽

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM