使用Zend Framework setTagsAllowed getTagsAllowed?

Mic*_*lle 1 zend-framework zend-filter-strip-tags

关于使用Zend Framework的Zend_Filter_StripTags 的setTagsAllowedgetTagsAllowed方法,我有一些非常基本的问题吗?特别:

  1. 标签列表应该在哪里定义?在应用程序的控制器中?
  2. 数组是否必须包含<> eg '<h1>'或'h1'?
  3. 阵列是否必须包含结束标记,例如'</h1>'

一个例子将不胜感激.

Cal*_*son 7

标签列表应该在哪里定义?在应用程序的控制器中?

你可以这样做.如果您可能在应用程序的其他位置重用该列表,则可能需要考虑使用Zend_Registry.

阵列是否必须包含<> ......?

只是'h1'.例如:

$allowedTags = array(
'a',
'b',
'em',
'strong'
);
Run Code Online (Sandbox Code Playgroud)

阵列是否必须包含结束标签......?

没有.

一个例子将不胜感激.

当然:

// permit only the <a>, <b>, <em> and <strong> tags
$allowedTags = array('a','b','em','strong');

// allow only the href attribute to be used in the above tags 
// (which should only be within the <a> tag anyway)
$allowedAttributes = array('href');

// create an instance of Zend_Filter_StripTags to use
$stripTags = new Zend_Filter_StripTags($allowedTags,$allowedAttributes);

// now filter the string
$sanitizedInput = $stripTags->filter($userInput);
Run Code Online (Sandbox Code Playgroud)

这回答了你的问题了吗?