我会为此创建一个控制器动作助手:
class My_Controller_Action_Helper_StripTags extends
Zend_Controller_Action_Helper_Abstract
{
/**
* StripTags
*
* @param string $input String to strip tags from
*
* @return string String without tags
*/
public function stripTags($input)
{
$allowedTags = array('p','b','br','strong'); // Allowed tags
$allowedAttributes = array('href'); // Allowed attributes
$stripTags = new Zend_Filter_StripTags($allowedTags,$allowedAttributes);
// return input without tags
return $stripTags->filter($input);
}
}
// example in indexAction
$noTags = $this->_helper->stripTags('<h2>TEST</h2>');
您必须在 application.ini 中添加助手的路径:
resources.frontController.actionhelperpaths.My_Controller_Action_Helper_ = "My/Controller/Action/Helper"