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

其调用方法如下,一:

$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. Android LayoutInflater原理分析

    相信接触Android久一点的朋友对于LayoutInflater一定不会陌生,都会知道它主要是用于加载布局的.而刚接触Android的朋友可能对LayoutInflater不怎么熟悉,因为加载布局的 ...

  2. [转]Linq中GroupBy方法的使用总结

    Demo模型类: public class StudentScore { public int ID { set; get; } public string Name { set; get; } pu ...

  3. grails-shiro权限认证

    一.引用shiro插件 //在BuildConfig的plugins下面添加 compile ":shiro:1.2.1" 二.引用新插件后要进行编译 //grails命令 com ...

  4. Java动态代理 cglib

    代理模式:为某些对象提供代理以实现对这个对象的访问. 对一个对象进行访问控制的原因是为了只有在我们确实需要这个对象时才对它进行创建和初始化. 一般包括以下组件: 被代理者接口:提供被代理者的访问途径. ...

  5. MIME协议生成邮件

    MIME协议生成一封复杂的邮件 MIME协议是对RFC822文档的升级和补充,用MIME协议能生成一封有文字.图片和附件的复杂邮件.首先要导入activation.jar和mail.jar.Mail. ...

  6. HTMl中Meta标签详解以及meta property=og标签含义

    meta是用来在HTML文档中模拟HTTP协议的响应头报文.META标签是HTML语言HEAD区的一个辅助性标签,它位于HTML文档头部的<HEAD>标记和<TITLE>标记之 ...

  7. [SAP ABAP开发技术总结]Form(subroutine)、Function参数传值传址

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  8. [SAP ABAP开发技术总结]字符串处理函数、正则表达式

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  9. implement "slam_karto" package in Stage simulation

    slam_karto ROS Wiki: http://wiki.ros.org/slam_karto Source: https://github.com/ros-perception/slam_k ...

  10. 本地设置正常,放服务器上就报 System.Security系统找不到指定的文件解决方法

    在应用程序池设置中将“加载用户配置文件”(Load User Profile)设置为true,问题就解决.