使用 Zend 框架 setTagsAllowed getTagsAllowed? [英] Use of Zend Framework setTagsAllowed getTagsAllowed?

查看:23
本文介绍了使用 Zend 框架 setTagsAllowed getTagsAllowed?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 setTagsAllowedgetTagsAllowed 方法与 Zend Framework 的 Zend_Filter_StripTags 一起使用?具体:

  1. 标签列表应该放在哪里定义?在应用程序的控制器?
  2. 数组是否必须包括 <> 例如 '

    ' 或只是'h1'?

  3. 数组是否必须包含结束标记,例如 ''?

一个例子将不胜感激.

解决方案

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

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

<块引用>

数组是否必须包含 <> ... ?

只是'h1'.例如:

$allowedTags = array('一种','b','他们','强的');

<块引用>

数组是否必须包含结束标记...?

没有

<块引用>

一个例子将不胜感激.

当然:

//只允许 ;和<strong>标签$allowedTags = array('a','b','em','strong');//只允许在上面的标签中使用 href 属性//(无论如何应该只在<a>标签内)$allowedAttributes = array('href');//创建 Zend_Filter_StripTags 的一个实例来使用$stripTags = new Zend_Filter_StripTags($allowedTags,$allowedAttributes);//现在过滤字符串$sanitizedInput = $stripTags->filter($userInput);

这是否回答了您的问题?

I have some very fundamental questions about the use of the setTagsAllowed and getTagsAllowed methods used with Zend Framework's Zend_Filter_StripTags? Specifically:

  1. Where should the list of tags defined? In the application's controller?
  2. Does the array have to include the <> eg '<h1>' or just 'h1'?
  3. Does the array have to include the closing tags eg '</h1>'?

An example would be appreciated.

解决方案

Where should the list of tags defined? In the application's controller?

You could do that. If you're likely to reuse the list elsewhere in your application, you might want to consider using Zend_Registry.

Does the array have to include the <> ... ?

Just 'h1'. For example:

$allowedTags = array(
'a',
'b',
'em',
'strong'
);

Does the array have to include the closing tags ... ?

No.

An example would be appreciated.

Sure:

// 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);

Does this answer your question?

这篇关于使用 Zend 框架 setTagsAllowed getTagsAllowed?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆