博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
phalcon: 过滤(Phalcon\Filter())
阅读量:4582 次
发布时间:2019-06-09

本文共 1460 字,大约阅读时间需要 4 分钟。

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

其调用方法如下,一:

$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  function
trim Applies the  function
lower Applies the  function
upper Applies the  function

 

 

转载于:https://www.cnblogs.com/achengmu/p/5914455.html

你可能感兴趣的文章
Java day1
查看>>
开始博客+生活+学习
查看>>
Ymodem协议-接收
查看>>
如何删除驱动精灵
查看>>
Web.py Cookbook 简体中文版 - web.input
查看>>
tomcat 启用NIO
查看>>
动态规划01
查看>>
再次遇到\r\n转\r问题
查看>>
运行APP显示两个APP图标,一个打不开,删除一个后,另一个也会消失。
查看>>
4. HTML5
查看>>
How to get a stack trace on Windows zz
查看>>
jquery 方面知识
查看>>
拖动弹出框
查看>>
java 泛型的使用
查看>>
find命令之exec和xargs
查看>>
添加Nginx为系统服务(设置开机启动)
查看>>
poj 2661 Factstone Benchmark (Stirling数)
查看>>
POJ3264 Balanced Lineup
查看>>
POJ 3468 A Simple Problem with Integers
查看>>
POJ Bookshelf 2(DFS)
查看>>