Home  >  Article  >  Backend Development  >  filter_var php

filter_var php

WBOY
WBOYOriginal
2016-08-08 09:22:161146browse

FILTER_CALLBACK

function myfilter($val)
{
    if(in_array($val, ['one','two','three'])){
        return false;
    }else
    return $val;
}
function test($str)
{
    $opti
    $rs=filter_var($str,FILTER_CALLBACK,$options);
    var_dump($rs);
    echo '<br>';
}
test('one');
test('aaa');
test(['bbb','two','123']);

Results:

bool(false) 
string(3) "aaa" 
array(3) { [0]=> string(3) "bbb" [1]=> bool(false) [2]=> string(3) "123" } 

FILTER_VALIDATE_INT

function test($num)
{
    $opti
    $rs=filter_var($num,FILTER_VALIDATE_INT,$options);
    var_dump($rs);
    echo '<br>';
}
test(99);
test(120);
test(250);

Results:
int(130) 
int(120) 
int(130) 

The above introduces filter_var php, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn