Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Mar 2007
    Location
    UK
    Posts
    151
    Thanks
    9
    Thanked 2 Times in 2 Posts

    Filter_var issue

    I'm writing a sanitizer, which runs filter_var and I'm passing the filter in a function call like
    PHP Code:
    $Filter = array('Email' => 'FILTER_SANITIZE_EMAIL');
    $Sanitizer = new Sanitizer();
    foreach(
    $_POST as $PostKey => $PostValue){
        
    $Sanitized $Sanitizer->Sanitize($PostValue$Filter[$PostKey]);

    When I run the code I get this error:
    Code:
    Warning: filter_var() expects parameter 2 to be long, string given.
    I'm just passing the filter value as it is. As the error says it expects a long I've tried typecasting the filter as a int, but that just changes it to a 0, on the PHP Manual there are no numbers which correspond to each filter. Any ideas of how to fix this?
    Thanks for any help.
    Last edited by tyanque; 04-11-2012 at 07:39 PM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    We can't see the actual filter_var call, but if it does what I think you are doing then the problem is the 'FILTER_SANITIZE_EMAIL'. This is a constant representing a bitwise value. That should simply be FILTER_SANITIZE_EMAIL without the quotes.

    Edit:
    Oh yeah one other possible solution. If for whatever reason these have to be strings (such as stored in a db), then you may invoke it by calling the constant() function to determine the value from the string name.
    Last edited by Fou-Lu; 04-11-2012 at 07:29 PM.

  • Users who have thanked Fou-Lu for this post:

    tyanque (04-11-2012)

  • #3
    Regular Coder
    Join Date
    Mar 2007
    Location
    UK
    Posts
    151
    Thanks
    9
    Thanked 2 Times in 2 Posts
    It issue with it being in quotes fixed it. Thanks for the help.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •