xref: /PHP-5.4/ext/filter/tests/021.phpt (revision 2c3db736)
1--TEST--
2filter_var() and FILTER_SANITIZE_NUMBER_*
3--SKIPIF--
4<?php if (!extension_loaded("filter")) die("skip"); ?>
5--FILE--
6<?php
7
8var_dump(filter_var("qwertyu123456dfghj", FILTER_SANITIZE_NUMBER_INT));
9var_dump(filter_var("asd123123.asd123.23", FILTER_SANITIZE_NUMBER_INT));
10var_dump(filter_var("123,23", FILTER_SANITIZE_NUMBER_INT));
11var_dump(filter_var("", FILTER_SANITIZE_NUMBER_INT));
12var_dump(filter_var("0", FILTER_SANITIZE_NUMBER_INT));
13var_dump(filter_var("asd123.2asd", FILTER_SANITIZE_NUMBER_INT));
14var_dump(filter_var("qwertyuiop", FILTER_SANITIZE_NUMBER_INT));
15var_dump(filter_var("123.4", FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION));
16var_dump(filter_var("123,4", FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION));
17var_dump(filter_var("123.4", FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_THOUSAND));
18var_dump(filter_var("123,4", FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_THOUSAND));
19var_dump(filter_var("123.4e", FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_SCIENTIFIC));
20var_dump(filter_var("123,4E", FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_SCIENTIFIC));
21var_dump(filter_var("qwe123,4qwe", FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION));
22var_dump(filter_var("werty65456.34", FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION));
23var_dump(filter_var("234.56fsfd", FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION));
24var_dump(filter_var("", FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION));
25
26echo "Done\n";
27?>
28--EXPECT--
29string(6) "123456"
30string(11) "12312312323"
31string(5) "12323"
32string(0) ""
33string(1) "0"
34string(4) "1232"
35string(0) ""
36string(5) "123.4"
37string(4) "1234"
38string(4) "1234"
39string(5) "123,4"
40string(5) "1234e"
41string(5) "1234E"
42string(4) "1234"
43string(8) "65456.34"
44string(6) "234.56"
45string(0) ""
46Done
47