在php中撤消strip_tags

时间:2012-06-21 18:24:32

标签: php wordpress

我正在尝试自定义Word新闻模板并遇到一些麻烦。该页面为http://rexonmedia.com/?page_id=113,每个部分下都有描述,描述中的所有文本都是纯文本(Actionscript,访问网站...)。我想要格式化文本或者像源(http://rexonmedia.com/?portfolio=audiomaya)这样的链接和超链接。

我发现这里的罪魁祸首是" strip_tags"标签。它用于两个不同的地方。我尝试了几个场景,但没有奏效。请帮忙

   public function customFormat($content,$strip_tags = false,$shortcode=true){
   $content =   stripslashes($content);
   if($shortcode)
   $content = do_shortcode( shortcode_unautop( $content ) ); 
   $content = preg_replace('#^<\/p>|^<br\s?\/?>|<p>$|<p>\s*(&nbsp;)?\s*<\/p>#', '', $content);

   if($strip_tags)
     $content = strip_tags($content,"<hades>,<tabend>");

   return $content;

    }   

<?php  
global $more;    // Declare global $more (before the loop).
    $more = 1;
$content = get_the_content('');
$content = apply_filters('the_content', $content);
    $content = str_replace(']]>', ']]&gt;', $content);
$this->shortenContent( $content_limit ,  strip_tags( $content  ) ); 
?>

1 个答案:

答案 0 :(得分:1)

为strip_tags提供允许的标签。第一个代码块中的行将更改为:

$content = strip_tags($content,"<strong><a>");

第二个代码块中的行将更改为:

$this->shortenContent( $content_limit ,  strip_tags( $content, "<strong><a>" ) ); 

顺便说一下,如果没有提供,函数会在函数定义中将$ strip_tags定义为false。检查一下!

public function customFormat($content,$strip_tags = false,$shortcode=true){