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 8810899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:13:51+00:00 2026-06-14T03:13:51+00:00

How to get POST variable using regex like this: $var = $_POST[‘foo?’]; or $var

  • 0

How to get POST variable using regex like this:

$var = $_POST['foo?'];

or

$var = $_POST['foo\w{1}'];

Edit:

My form has many buttons with separate names: file1, file2, file3. When pressing a button, of course it pass file1 or file2, … I want to get the value using that name.

  • 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-06-14T03:13:52+00:00Added an answer on June 14, 2026 at 3:13 am

    The easiest thing I can think of is this:

    $allPostKeys = implode(',',array_keys($_POST));
    $wildcardVals = array();
    if (preg_match_all('/,?(foo[0-9]),?/',$allPostKeys,$matches))
    {
        $wildCardKeys = $matches[1];
        while($key = array_shift($wildCardKeys))
        {
            $wildcardVals[$key] = $_POST[$key];
        }
    }
    if (!empty($wildcardVals))
    {//do stuff with all $_POST vals that you needed
    }
    

    Replace [0-9] in the regex with . to match any char, or whatever you need to see matched.
    Tested this out with an array that had the following keys bar,zar,foo1,foo2,foo3, and it returned array('foo1' => 'val1','foo2' => 'val2','foo3' => 'val3'), which is what you need, I think.

    In response to your edit
    The $_POST super-global can be a multi dimensional array, too:

    <input type="file" name="file[]" id="file1"/>
    <input type="file" name="file[]" id="file2"/>
    <input type="file" name="file[]" id="file3"/>
    

    That way, you can easily loop through the files:

    foreach($_POST['file'] as $file)
    {
        //process each file individually: $file is the value
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to get value of the get or post variable on page load using
I am trying to get post a form to a hidden, dynamically inserted iframe,
I would like to get POST data sent to page controller in init() function
Using Basic Authentication, and the asp.net Web-Api, where JSON Get/Post's to my API, I
i want to know what are the vulnerabilities while using the GET and POST
Let's say my $_POST variable looks like: <?php Array ( [user_ID] => 65 [action]
Codes ####### The name of this file is 'test_ajaxfn.php' ####### <?php if($_POST['var']) { $result
I'm wondering how to go about obtaining the value of a POST/GET request variable
Shortened Aim: To pass a variable via $.POST to a PHP file (get.php), and
Possible Duplicate: how to get GET and POST variables with JQuery? I have the

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.