过滤,就是清除不需要的数据,留下想要的数据。

其调用方法如下,一:

$filter = new \Phalcon\Filter();
$filter->sanitize("some(one)@exa\mple.com", "email"); 得到的结果是:"someone@example.com"

  

另外一种方法是:

直接通过getPost/get获取

//gby(one)ftk\wf@qq.com
$email = $this->request->getPost("email", "email");
echo $email;
//gbyoneftkwf@qq.com
//$this->request->getPost("参数名", "email(需要验证的规则)");

  

自定义过滤器:

案一:
class IPv4Filter
{ public function filter($value)
{
return filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);
} } $filter = new \Phalcon\Filter(); //Using an object
$filter->add('ipv4', new IPv4Filter()); //Sanitize with the "ipv4" filter
$filteredIp = $filter->sanitize("127.0.0.1", "ipv4"); 案二:
$filter = new \Phalcon\Filter(); //Using an anonymous function
$filter->add('md5', function($value) {
return preg_replace('/[^0-9a-f]/', '', $value);
}); //Sanitize with the "md5" filter
$filtered = $filter->sanitize($possibleMd5, "md5");

  

内置过滤器类型(Types of Built-in Filters)

The following are the built-in filters provided by this component:

Name Description
string Strip tags
email Remove all characters except letters, digits and !#$%&*+-/=?^_`{|}~@.[].
int Remove all characters except digits, plus and minus sign.
float Remove all characters except digits, dot, plus and minus sign.
alphanum Remove all characters except [a-zA-Z0-9]
striptags Applies the strip_tags function
trim Applies the trim function
lower Applies the strtolower function
upper Applies the strtoupper function

phalcon: 过滤(Phalcon\Filter())的更多相关文章

  1. 匿名函数lambda,过滤函数filter,映射类型map

    匿名函数lambda, 作用是不用定义函数,用完之后会自动被删掉,在使用执行脚本的时候,使用lambda就可以省下定义函数的过程,简化代码的可读性. 格式是 例子g=lambda x,y:x+y g( ...

  2. hbase 基本的JavaApi 数据操作及数据过滤(filter)

    本文主要是hbase的表操作.数据操作.数据查询过滤等,如果对JDBC或ADO有了解,容易理解HBASE API. hbase版本是2.0. 1.为了方便先贴helper的部分代码(文末git上有完整 ...

  3. 在.NET下学习Extjs(第三个案例 Array的过滤方法(filter))

    Ext.Array.filter(Array array,Function fn,Object scope):Array array是一个数组,fn是过滤函数,scope是作用域,filter返回的是 ...

  4. 大数据量下的集合过滤—Bloom Filter

    算法背景 如果想判断一个元素是不是在一个集合里,一般想到的是将集合中所有元素保存起来,然后通过比较确定.链表.树.散列表(又叫哈希表,Hash table)等等数据结构都是这种思路,存储位置要么是磁盘 ...

  5. 过滤函数 filter

    filter(lambda x:x.endswith('居'),house_type_list) 过滤函数,作用就是将“以‘居’结尾的字段都过滤出来,其它的字段都删除掉.”

  6. WPF中DataGrid控件的过滤(Filter)性能分析及优化

    DataGrid控件是一个列表控件, 可以进行过滤,排序等.本文主要针对DataGrid的过滤功能进行分析, 并提供优化方案. 1)DataGrid的过滤过程:      用户输入过滤条件       ...

  7. django model 条件过滤 queryset.filter(**condtions) 用法

    1.下述代码查询model对应数据库中日期等于2018-05-22的数据: queryset = model.objects.all() condtions: {'date': '2018-05-22 ...

  8. Yii 日期时间过滤列 filter

    在yii使用过程中,我们经常要使用到 按时间区间来检索数据 用gridview自身的filter就无法满足我们得需求. 下面可以用插件的方式来搞定: sydatecolumn 下载地址:http:// ...

  9. 过滤函数filter

    >>> def validate(usernames): if (len(usernames) > 4) and (len(usernames) < 12): retur ...

随机推荐

  1. python代码

    f=open('/home/xbwang/newtextsimilarity/data/glove/glove.840B.300d.txt','r') count = 0 print ' '.join ...

  2. HTTP断点续传的基本原理

    转自:http://blog.csdn.net/sendy888/article/details/1719105 断点续传是我们现在经常接触的概念,那么HTTP协议是如何支持断点续传的呢.我们先从一个 ...

  3. 双4G LTE

    我们即将上市的Xplay3S将支持双4G LTE(TDD-LTE+FDD-LTE),那什么是4G LTE呢,今天来给大家科普下4G LTE网络知识. 什么是TDD-LTE/FDD-LTE? LTE是通 ...

  4. (转)eclipse 导入Android 项目 步骤

    1.打开eclipse 2. 点击File--选择-->Import,会出来图片,如图 3.按上面的点击android下的Existing Android...出来画面,如下图   4.点击Br ...

  5. Win 64 register usage

    http://www.mouseos.com/win64/registers.html Seems UEFI using rcx, rdx, r8, r9, r10, r11, r12 to stor ...

  6. window删除损坏无法打开的文件

    移动硬盘删除文件时提示“文件或目录损坏且无法读取”的解决方法-chkdsk 命令的巧用 新买一个移动硬盘,同学借去Copy一个游戏,拷来后发现数据包损坏,提示"文件或目录损坏且无法读取&qu ...

  7. ubuntu下ssh登陆阿里云服务器(ubuntu系统)中文乱码问题

    研究了几天终于解决了... 原文地址:  http://blog.csdn.net/a__yes/article/details/50489456 问题描述: 阿里云的服务器ubuntu系统,wind ...

  8. Examples For PLSQL Cursors - Explicit, Implicit And Ref Cursors

    A cursor acts logically as a pointer into a result set. You can move the cursor through the result s ...

  9. Reading Csv Files with Text_io in Oracle D2k Forms

    Below is the example to read and import comma delimited csv file in oracle forms with D2k_Delimited_ ...

  10. django 的auth.authenticate返回为None

    使用auth.authenticate(username= username,passowrd=passowrd),这个用户认证时候,明明数据库中有记录,但是返回就None 我的错误点比较多: 1.我 ...