How to grab all variables in a post (PHP)

前端 未结 5 1792
忘了有多久
忘了有多久 2020-12-10 04:54

How to grab all variables in a post (PHP)? I don\'t want to deal with $_POST[\'var1\']; $_POST[\'var2\']; $_POST[\'var3\']; ... I want to echo all of them in on

相关标签:
5条回答
  • 2020-12-10 05:08

    If you want the POST values as variables in your script, you can use the extract function, e.g.

    extract ( $_GET );
    

    or

    extract ( $_GET, EXTR_IF_EXISTS );
    

    There are several flags you can use (check the manual); this one restricts extraction to variables already defined.

    You can also use the import_request_variables function.

    Cheers

    Jeff

    0 讨论(0)
  • 2020-12-10 05:08

    Use this function in a loop. extract ( $_GET );

    0 讨论(0)
  • 2020-12-10 05:20
    echo '<pre>'; 
    print_r($_POST); 
    echo '</pre>';
    
    0 讨论(0)
  • 2020-12-10 05:28

    If you really just want to print them, you could do something like:

    print_r($_POST);
    

    Alternatively, you could interact with them individually doing something like:

    foreach ($_POST as $key => $value) {
        //do something
        echo $key . ' has the value of ' . $value;
    }
    

    but whatever you do.. please filter the input. SQL Injection gives everyone sleepless nights.

    0 讨论(0)
  • 2020-12-10 05:29

    Use:

    var_dump($_POST);
    
    0 讨论(0)
提交回复
热议问题