xref: /PHP-5.3/ext/filter/tests/filter_data.phpt (revision ffd09c09)
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 = "123";    var_dump(filter_var($data, FILTER_VALIDATE_INT));
14$data = -123;     var_dump(filter_var($data, FILTER_VALIDATE_INT));
15$data = 0;        var_dump(filter_var($data, FILTER_VALIDATE_INT));
16$data = 123;      var_dump(filter_var($data, FILTER_VALIDATE_INT));
17$data = "";       var_dump(filter_var($data, FILTER_VALIDATE_INT));
18echo "\n";
19
20/* Float */
21$data = "-0.123"; var_dump(filter_var($data, FILTER_VALIDATE_FLOAT));
22$data = "0.00";   var_dump(filter_var($data, FILTER_VALIDATE_FLOAT));
23$data = "1.23";   var_dump(filter_var($data, FILTER_VALIDATE_FLOAT));
24$data = -1.23;    var_dump(filter_var($data, FILTER_VALIDATE_FLOAT));
25$data = 0.0;      var_dump(filter_var($data, FILTER_VALIDATE_FLOAT));
26$data = 1.23;     var_dump(filter_var($data, FILTER_VALIDATE_FLOAT));
27$data = "";       var_dump(filter_var($data, FILTER_VALIDATE_FLOAT));
28echo "\n";
29
30/* Boolean */
31$data = "on";     var_dump(filter_var($data, FILTER_VALIDATE_BOOLEAN));
32$data = "off";    var_dump(filter_var($data, FILTER_VALIDATE_BOOLEAN));
33$data = "yes";    var_dump(filter_var($data, FILTER_VALIDATE_BOOLEAN));
34$data = "no";     var_dump(filter_var($data, FILTER_VALIDATE_BOOLEAN));
35$data = "true";   var_dump(filter_var($data, FILTER_VALIDATE_BOOLEAN));
36$data = "false";  var_dump(filter_var($data, FILTER_VALIDATE_BOOLEAN));
37$data = "1";      var_dump(filter_var($data, FILTER_VALIDATE_BOOLEAN));
38$data = "0";      var_dump(filter_var($data, FILTER_VALIDATE_BOOLEAN));
39$data = 1;        var_dump(filter_var($data, FILTER_VALIDATE_BOOLEAN));
40$data = 0;        var_dump(filter_var($data, FILTER_VALIDATE_BOOLEAN));
41$data = true;     var_dump(filter_var($data, FILTER_VALIDATE_BOOLEAN));
42$data = false;    var_dump(filter_var($data, FILTER_VALIDATE_BOOLEAN));
43$data = "";       var_dump(filter_var($data, FILTER_VALIDATE_BOOLEAN));
44
45?>
46--EXPECT--
47int(-123)
48int(0)
49int(123)
50int(-123)
51int(0)
52int(123)
53bool(false)
54
55float(-0.123)
56float(0)
57float(1.23)
58float(-1.23)
59float(0)
60float(1.23)
61bool(false)
62
63bool(true)
64bool(false)
65bool(true)
66bool(false)
67bool(true)
68bool(false)
69bool(true)
70bool(false)
71bool(true)
72bool(false)
73bool(true)
74bool(false)
75bool(false)
76