【问题标题】:CakePHP: Strip HTML using Text helper?CakePHP:使用文本助手剥离 HTML?
【发布时间】:2011-04-22 19:53:05
【问题描述】:

我正在使用文本助手的 truncate 方法,这样做意味着文本中包含的任何 html 都将被呈现。无论如何设置文本助手以去除html标签?

           echo $text->truncate(    
                $project['Project']['description'], 
                250,   
                array(
                    'ending' => '...', 
                    'exact' => false
                )
            );

是否有类似 stripLinks 方法的修改?

谢谢,

琼斯

【问题讨论】:

    标签: php cakephp helper


    【解决方案1】:
    echo $text->truncate(    
                $project['Project']['description'], 
                250,   
                array(
                    'ending' => '...', 
                    'exact' => false,
                    'html' => true
                )
            );
    

    这将使其尊重 html 结构。你总是可以使用 strip_tags(),在 cake 中使用 php 函数没有错 :)

    【讨论】:

      【解决方案2】:

      是的,你应该使用Sanitize::html($badString)
      the documentation

      【讨论】:

      • 如果我错了,请纠正我,但这不会只是将 html 标签更改为文本。所以它会显示 html 标签,但不会显示为 html
      • $options 数组中使用'remove' => true 会删除HTML 标记。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-27
      • 2011-06-04
      • 2011-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多