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);
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.