Programmer's Reference Guide
| 简介 |
标准过滤器类
Zend Framework 带有一组标准的过滤器。
Alnum
返回只保留字母和数字的字符串 $value,这个过滤器包括一个允许空白字符的选项。
Alpha
返回只保留字母的字符串 $value,这个过滤器包括一个允许空白字符的选项。
BaseName
给定包含一个文件的路径字符串,这个过路器将返回这个文件的基本名(base name)。
Digits
返回只保留数字的字符串 $value。
Dir
返回路径的名字部分。
HtmlEntities
返回转换成它们对应 HTML 实体的字符串 $value。
Int
返回整数 $value。
StripNewlines
返回不带任何新行控制符的字符串 $value 。
RealPath
扩展所有符号的链接和解析指向在输入路径里的 '/./', '/../' 和额外的 '/' 字符并且返回规范化后的绝对路径名,返回的结果路径将没有符号链接 '/./' 或 '/../' 部分。
如果失败,例如文件不存在,Zend_Filter_RealPath 将返回 FALSE。在 BSD 系统,如果只有路径最后部分不存在, Zend_Filter_RealPath 不会失败,但其它系统返回 FALSE。
StringToLower
返回按需转换字母成小写的字符串 $value。
StringToUpper
返回按需转换字母成大写的字符串 $value。
StringTrim
返回从头到尾整理过的字符串 $value。
StripTags
返回把 HTML 和 PHP 标签已剥离的(声明为允许的标签不会剥离)输入的字符串。除了能指定允许哪个标签,开发者也可以在所有允许的标签(或只对特定的标签)中指定哪个属性被允许。最后,这个过滤器提供控制是否注释(如 <!-- ... -->)被删除或允许。
| 简介 |
Add A Comment
Please do not report issues via comments; use the ZF Issue Tracker.
If you have a JIRA/Crowd account, we suggest you login first before commenting.

Comments
$form = new Zend_Form();
$form->addElement('text', 'name', array(
'filters' => array(
array('StripTags', array(array(
'allowTags' => array('p', 'br', 'strong'),
'allowAttribs' => array('style', 'title')
)))
)
));
$form = new Zend_Form();
$form->addElement('text', 'name', array(
'filters' => array(
array('StripTags', array(array(
'allowTags' => array('p', 'br', 'strong'),
'allowAttribs' => array('style', 'title')
)))
)
));
$form = new Zend_Form();
$form->addElement('text', 'name', array(
'filters' => array(
array('StripTags', array(array(
'allowTags' => array('p', 'br', 'strong'),
'allowAttribs' => array('style', 'title')
)))
)
));
$form = new Zend_Form();
$form->addElement('text', 'name', array(
'filters' => array(
array('StripTags', array(array(
'allowTags' => array('p', 'br', 'strong'),
'allowAttribs' => array('style', 'title')
)))
)
));
$fl = new Zend_Filter_PregReplace('/([^0-9a-z_])*/i', '');
$username = $fl->filter($this->_request->getPost('username', ''));
$form = new Zend_Form();
$form->addElement('text', 'name', array(
'filters' => array(
array('StripTags', array('options' => array(
'allowTags' => array('p', 'br', 'strong'),
'allowAttribs' => array('style', 'title')
)))
)
));
My Zend 1.10.8 does not work as described above. For instance in the example:
$filter = new Zend_Filter_Int();
print $filter->filter('-4 is less than 0');
This will return '-4'.
...in my case it will return 0. There's not even any code in zend/filter/int.php that would remove non numeric values in my installation.
Also, I am somehow able to accomplish a situation where Zend_Filter_Boolean(); always returns true no matter what I try to do with it.
Coud it be that something's not loading properly, or I have some setting missing or I have failed to install Zend correctly?
To compress a file use the following:
$filter = new Zend_Filter_Compress(array(
'adapter' => 'Bz2',
'options' => array(
'archive' => 'filename.bz2'
),
));
$compressed = $filter->filter(file_get_contents(compressme.txt));
As when I pass this expression with text in a text node through php string e.g. $string = $textvalue."<br>";
and then passing $string to attribute text like
$root->appendChild($xmlDoc->createAttribute("caption"))->appendChild($xmlDoc->createTextNode($string ));
But, brouhaha... this generates textnode like
<root caption="&lt;BR&gt;">
</root>
This means some extra characters "amp;" are also added. So the parsed XML won't give a line break as &lt;BR&gt; will be recognized as plain text <br> and prints the same i.e. <br> as text.
The source code shows this:
$zip = new ZipArchive();
$res = $zip->open($this->getArchive(), ZipArchive::CREATE | ZipArchive::OVERWRITE);
Can someone fix it?
My workaround for this is to use the full ZF1 namespaced name for the adapter, like so:
$filter = new Zend_Filter_Decompress(array(
'adapter' => 'Zend_Filter_Compress_Zip',
'options' => array(
'target' => $target_directory,
)
));