xref: /PHP-7.4/ext/filter/tests/011.phpt (revision 17ccbeec)
1--TEST--
2filter_input()
3--INI--
4precision=14
5--SKIPIF--
6<?php if (!extension_loaded("filter")) die("skip"); ?>
7--GET--
8a=<b>test</b>&b=http://example.com
9--POST--
10c=<p>string</p>&d=12345.7
11--FILE--
12<?php
13ini_set('html_errors', false);
14var_dump(filter_input(INPUT_GET, "a", FILTER_SANITIZE_STRIPPED));
15var_dump(filter_input(INPUT_GET, "b", FILTER_SANITIZE_URL));
16var_dump(filter_input(INPUT_GET, "a", FILTER_SANITIZE_SPECIAL_CHARS, array(1,2,3,4,5)));
17var_dump(filter_input(INPUT_GET, "b", FILTER_VALIDATE_FLOAT, new stdClass));
18var_dump(filter_input(INPUT_POST, "c", FILTER_SANITIZE_STRIPPED, array(5,6,7,8)));
19var_dump(filter_input(INPUT_POST, "d", FILTER_VALIDATE_FLOAT));
20var_dump(filter_input(INPUT_POST, "c", FILTER_SANITIZE_SPECIAL_CHARS));
21var_dump(filter_input(INPUT_POST, "d", FILTER_VALIDATE_INT));
22
23var_dump(filter_var(new stdClass, "d"));
24
25var_dump(filter_input(INPUT_POST, "c", "", ""));
26var_dump(filter_var("", "", "", "", ""));
27var_dump(filter_var(0, 0, 0, 0, 0));
28
29echo "Done\n";
30?>
31--EXPECTF--
32string(4) "test"
33string(18) "http://example.com"
34string(27) "&#60;b&#62;test&#60;/b&#62;"
35
36Notice: Object of class stdClass could not be converted to int in %s011.php on line %d
37bool(false)
38string(6) "string"
39float(12345.7)
40string(29) "&#60;p&#62;string&#60;/p&#62;"
41bool(false)
42
43Warning: filter_var() expects parameter 2 to be int, string given in %s011.php on line %d
44NULL
45
46Warning: filter_input() expects parameter 3 to be int, string given in %s011.php on line %d
47NULL
48
49Warning: filter_var() expects at most 3 parameters, 5 given in %s011.php on line %d
50NULL
51
52Warning: filter_var() expects at most 3 parameters, 5 given in %s011.php on line %d
53NULL
54Done
55