1--TEST-- 2Simple filter_var() tests 3--SKIPIF-- 4<?php if (!extension_loaded("filter")) die("skip"); ?> 5--INI-- 6precision=14 7--FILE-- 8<?php 9 10/* Integer */ 11$data = "-123"; var_dump(filter_var($data, FILTER_VALIDATE_INT)); 12$data = "0"; var_dump(filter_var($data, FILTER_VALIDATE_INT)); 13$data = "-0"; var_dump(filter_var($data, FILTER_VALIDATE_INT)); 14$data = "+0"; var_dump(filter_var($data, FILTER_VALIDATE_INT)); 15$data = "123"; var_dump(filter_var($data, FILTER_VALIDATE_INT)); 16$data = -123; var_dump(filter_var($data, FILTER_VALIDATE_INT)); 17$data = 0; var_dump(filter_var($data, FILTER_VALIDATE_INT)); 18$data = -0; var_dump(filter_var($data, FILTER_VALIDATE_INT)); 19$data = +0; var_dump(filter_var($data, FILTER_VALIDATE_INT)); 20$data = 123; var_dump(filter_var($data, FILTER_VALIDATE_INT)); 21$data = ""; var_dump(filter_var($data, FILTER_VALIDATE_INT)); 22echo "\n"; 23 24/* Float */ 25$data = "-0.123"; var_dump(filter_var($data, FILTER_VALIDATE_FLOAT)); 26$data = "0.00"; var_dump(filter_var($data, FILTER_VALIDATE_FLOAT)); 27$data = "1.23"; var_dump(filter_var($data, FILTER_VALIDATE_FLOAT)); 28$data = -1.23; var_dump(filter_var($data, FILTER_VALIDATE_FLOAT)); 29$data = 0.0; var_dump(filter_var($data, FILTER_VALIDATE_FLOAT)); 30$data = 1.23; var_dump(filter_var($data, FILTER_VALIDATE_FLOAT)); 31$data = ""; var_dump(filter_var($data, FILTER_VALIDATE_FLOAT)); 32echo "\n"; 33 34/* Boolean */ 35$data = "on"; var_dump(filter_var($data, FILTER_VALIDATE_BOOLEAN)); 36$data = "off"; var_dump(filter_var($data, FILTER_VALIDATE_BOOLEAN)); 37$data = "yes"; var_dump(filter_var($data, FILTER_VALIDATE_BOOLEAN)); 38$data = "no"; var_dump(filter_var($data, FILTER_VALIDATE_BOOLEAN)); 39$data = "true"; var_dump(filter_var($data, FILTER_VALIDATE_BOOLEAN)); 40$data = "false"; var_dump(filter_var($data, FILTER_VALIDATE_BOOLEAN)); 41$data = "1"; var_dump(filter_var($data, FILTER_VALIDATE_BOOLEAN)); 42$data = "0"; var_dump(filter_var($data, FILTER_VALIDATE_BOOLEAN)); 43$data = 1; var_dump(filter_var($data, FILTER_VALIDATE_BOOLEAN)); 44$data = 0; var_dump(filter_var($data, FILTER_VALIDATE_BOOLEAN)); 45$data = true; var_dump(filter_var($data, FILTER_VALIDATE_BOOLEAN)); 46$data = false; var_dump(filter_var($data, FILTER_VALIDATE_BOOLEAN)); 47$data = ""; var_dump(filter_var($data, FILTER_VALIDATE_BOOLEAN)); 48 49?> 50--EXPECT-- 51int(-123) 52int(0) 53int(0) 54int(0) 55int(123) 56int(-123) 57int(0) 58int(0) 59int(0) 60int(123) 61bool(false) 62 63float(-0.123) 64float(0) 65float(1.23) 66float(-1.23) 67float(0) 68float(1.23) 69bool(false) 70 71bool(true) 72bool(false) 73bool(true) 74bool(false) 75bool(true) 76bool(false) 77bool(true) 78bool(false) 79bool(true) 80bool(false) 81bool(true) 82bool(false) 83bool(false) 84