Nate
Nate

Reputation: 577

specify callback params for filter_var in php

I have this:

$value = filter_var($value, FILTER_CALLBACK, 'mysqli_real_escape_string');

and I'm getting the message:

Warning: filter_var() [function.filter-var]: First argument is expected to be a 
valid callback in C:\mypath\Database.class.php on line 285

but the manual clearly states that the first argument of filter_var is the input string, any ideas?

Upvotes: 2

Views: 2148

Answers (2)

Paul
Paul

Reputation: 141827

The docs are not very clear. The argument needs to be an array with the key options being your callable. In addition, mysqli_real_escape_string expects two arguments, the database link and the string:

$value = filter_var($value, FILTER_CALLBACK,
  array('options' => array('mysqli', 'real_esacpe_string')));

Upvotes: 4

u54r
u54r

Reputation: 1805

This is the syntax for FILTER_CALLBACK your callback should be in array. Since mysqli_real_escape_string takes two arguments, your code wouldn't work even if you followed right syntax. Try to make your own function.

$value = filter_var($value, FILTER_CALLBACK, array('options'=>'YOUR_CALLBACK_HERE'));

Upvotes: 3

Related Questions