【问题标题】:Use of Zend Framework setTagsAllowed getTagsAllowed?Zend Framework 使用 setTagsAllowed getTagsAllowed?
【发布时间】:2009-07-01 15:26:45
【问题描述】:
我有一些关于使用 Zend Framework 的 Zend_Filter_StripTags 的 setTagsAllowed 和 getTagsAllowed 方法的基本问题?具体来说:
- 标签列表应该放在哪里
定义?在应用程序的
控制器?
- 阵列是否必须
包括 例如
'<h1>' 或只是
'h1'?
- 数组是否必须包含
结束标签,例如
'</h1>'?
一个例子将不胜感激。
【问题讨论】:
标签:
zend-framework
zend-filter-strip-tags
【解决方案1】:
标签列表应该在哪里定义?在应用程序的
控制器?
你可以这样做。如果您可能在应用程序的其他地方重用该列表,您可能需要考虑使用 Zend_Registry。
数组必须包含 ... 吗?
只是'h1'。例如:
$allowedTags = array(
'a',
'b',
'em',
'strong'
);
数组是否必须包含结束标签...?
没有。
一个例子将不胜感激。
当然:
// 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);
这能回答你的问题吗?