regex - php code with filter_var_array()/ filter_input_array not working properly -
a test of php code below ideone.com gives 2 errors
"php warning: filter_var_array(): 'regexp' option missing in /home/rhlgyu/prog.php on line 18"
the line $myinputs = filter_var_array($data, $args)
.
it may beginners experience dont understand error message, e.g., dont know goes wrong in code below. checked 2 regex expressions definitions (regexp_multiple_names
, regexp_phone_nl
) , okay.
i suspect there error in definition of $args
, cant find (when compare examples in http://www.w3schools.com/php/filter_validate_regexp.asp).
php code:
define("regexp_multiple_names", "/^[a-za-z\s-]+$/i"); //expression check dutch phone numbers. number must start 0 , number of digits should 10. different area , country codes allowed. define("regexp_phone_nl", "/(^\+[0-9]{2}|^\+[0-9]{2}\(0\)|^\(\+[0-9]{2}\)\(0\)|^00[0-9]{2}|^0)([0-9]{9}$|[0-9\-\s]{10}$)/"); $data = array( 'city' => 'the hague', 'telephonenr' => '0701234567' ); $args = array( 'city' => array( 'filter' => filter_validate_regexp, array( "options" => array( "regexp" => regexp_multiple_names ) ) ), 'telephonenr' => array( 'filter' => filter_validate_regexp, array( 'options' => array( "regexp" => regexp_phone_nl ) ) ) ); $myinputs = filter_var_array($data, $args); print_r($myinputs);
looking @ php manual think suppose structured like:
$args = array( 'city' => array( 'filter' => filter_validate_regexp, 'options' => array( "regexp" => regexp_multiple_names ) ), 'telephonenr' => array( 'filter' => filter_validate_regexp, 'options' => array( "regexp" => regexp_phone_nl ) ) );
Comments
Post a Comment