xref: /PHP-8.2/ext/filter/tests/017.phpt (revision 74859783)
1--TEST--
2filter_var() and FILTER_VALIDATE_REGEXP
3--EXTENSIONS--
4filter
5--FILE--
6<?php
7
8var_dump(filter_var("data", FILTER_VALIDATE_REGEXP, array("options"=>array("regexp"=>'/.*/'))));
9var_dump(filter_var("data", FILTER_VALIDATE_REGEXP, array("options"=>array("regexp"=>'/^b(.*)/'))));
10var_dump(filter_var("data", FILTER_VALIDATE_REGEXP, array("options"=>array("regexp"=>'/^d(.*)/'))));
11var_dump(filter_var("data", FILTER_VALIDATE_REGEXP, array("options"=>array("regexp"=>'/blah/'))));
12var_dump(filter_var("data", FILTER_VALIDATE_REGEXP, array("options"=>array("regexp"=>'/\[/'))));
13try {
14    filter_var("data", FILTER_VALIDATE_REGEXP);
15} catch (ValueError $exception) {
16    echo $exception->getMessage() . "\n";
17}
18
19echo "Done\n";
20?>
21--EXPECT--
22string(4) "data"
23bool(false)
24string(4) "data"
25bool(false)
26bool(false)
27filter_var(): "regexp" option is missing
28Done
29