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

其调用方法如下,一:

$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. linux脚本随笔-01

    #### 获取配置文件配置路径,javapath为配置项,var为具体的配置值 eval $(awk -F "javapath=" '{if($2=="") { ...

  2. mysql分库分表

    1.分库分表 很明显,一个主表(也就是很重要的表,例如用户表)无限制的增长势必严重影响性能,分库与分表是一个很不错的解决途径,也就是性能优化途径,现在的案例是我们有一个1000多万条记录的用户表mem ...

  3. MFC之简单计算器

    1.界面 2.变量 combobox的变量类型是CComBoBox类型,三个输入框是double类型: 它的type是Drop List 3.代码 (1).初始化combobox BOOL Ccalc ...

  4. HTML DOM事件

    HTML DOM事件 1.HTML事件包括: (1)当用户点击鼠标时: (2)当页面已加载时: (3)当图像已加载时: (4)当鼠标移动到元素上时: (5)当输入字段被改变时: (6)当提交HTML表 ...

  5. iptraf:TCP/UDP网络监控工具

    原文:http://www.unixmen.com/iptraf-tcpudp-network-monitoring-utility/ 作者: Enock Seth Nyamador 译文:LCTT  ...

  6. IOS之分析网易新闻存储数据(CoreData的使用,增删改查)

    用过网易新闻客户端的朋友们都知道,获取新闻列表时有的时候他会请求网络有时候不会,查看某条新闻的时候再返回会标注已经查看的效果,接下来分析一下是如何实现的. 首先: 1.网易新闻用CoreData存储了 ...

  7. [CVE:2013-4810]Apache Tomcat/JBoss远程命令执行

    <?php $host=gethostbyname($argv[1]); $port=$argv[2]; $cmd=$argv[3]; //small jsp shell //change th ...

  8. CUBRID学习笔记 22 插入数据

    CREATE TABLE auto_tbl(id INT AUTO_INCREMENT, name VARCHAR); 自增长的列可以插入null, 同时一次可以插入多条记录.别的和其他的sql数据库 ...

  9. eclipse 实用快捷键

    Ctrl+E: 弹出输入窗口,可快速返回想返回的目标界面 Ctrl+Shift+O: 快速import包 Ctrl+O:显示类中方法和属性的大纲 Ctrl+1 快速修复 Ctrl+Alt+↓ 复制当前 ...

  10. TestNg测试框架使用笔记

    Gradle支持TestNG test { useTestNG(){ //指定testng配置文件 suites(file('src/test/resources/testng.xml')) } } ...