Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 379283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:52:36+00:00 2026-05-12T14:52:36+00:00

I have been toying with PHP filter library. I liked it but I am

  • 0

I have been toying with PHP filter library. I liked it but I am unable to perform a simple filter function. I essentially want to invalidate those values in my input array that are strings and which are longer than certain value.
Is there a way to do this like,

$data = array('input_string_array' => array('aaa', 'abaa', 'abaca'));
$args = array(
    'component'    => array('filter'    => FILTER_DEFAULT,
                            'flags'     => FILTER_REQUIRE_ARRAY, 
                            'options'   => array('min_length' => 1, 'max_length' => 10)
                           )
);

var_dump(filter_var_array($data, $args));

I tried this and its giving me error. because presumably there is no min_length/max_length option available. But then how to implement this? Also is there a place where it is mentioned about all such options like max_range, min_range, regexp.

Also I had another doubt, in filters, in FILTER_CALLBACK filter. I wanted to know if there is a way to pass a parameter other than the data to the called function? something like this,

echo filter_var($string, FILTER_CALLBACK, array("options"=> array("lengthChecker", "5")));

Thanks a lot for the help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T14:52:37+00:00Added an answer on May 12, 2026 at 2:52 pm

    Unless there’s a better, more direct filter+option you can use FILTER_VALIDATE_REGEXP

    $data = array('input_string_array' => array('', 'aaa', 'abaa', 'abaca'));
    $args = array(
      'input_string_array' => array(
        'filter' => FILTER_VALIDATE_REGEXP,
        'flags'     => FILTER_REQUIRE_ARRAY|FILTER_NULL_ON_FAILURE,
        'options'   => array('regexp'=>'/^.{1,3}$/')
      )
    );
    var_dump(filter_var_array($data, $args));
    

    prints

    array(1) {
      ["input_string_array"]=>
      array(4) {
        [0]=>
        NULL
        [1]=>
        string(3) "aaa"
        [2]=>
        NULL
        [3]=>
        NULL
      }
    }
    

    To get rid of the NULL elements you can use e.g. array_filter().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been toying with the JanRain OpenID PHP Library, mostly following along with a
I have been trying to output XML with PHP but encountered a strange(!) error
I have been trying to force images to download using PHP Headers but there
I have been trying to get the crc32 function from PHP to match results
Essentially I have been trying to think of a PHP-based solution to do the
I have been trying to figure this out, but couldn't. On php a multidimensional
I'm fairly new to PHP and have been trying to make a simple login
i have been trying to learn PHP Repeat Region... i have searched google but
I have been trying to display image from database using php but i am
I have been trying to create a simple calculator. Using PHP I managed to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.