PHP need to trim all the $_POST variables

前端 未结 8 1837
广开言路
广开言路 2021-01-01 23:14

Need you help in an unusal situation. I need to trim all the $_POST variables.

Is there any way I can do it at a single shot i.e., using a single function?

I

相关标签:
8条回答
  • 2021-01-02 00:04

    use array_walk with a custom function

    $clean_values = array();
    array_walk($_POST, 'sanitize_post');
    
    function sanitize_post($item, $key)
    {
        $clean_values[$key] = trim($item);
        //optional further cleaning ex) htmlentities
    }
    
    0 讨论(0)
  • 2021-01-02 00:06

    Simply use this:

    array_walk($_POST, create_function('&$val', '$val = trim($val);')); 
    

    and your $_POST is now trimmed.

    0 讨论(0)
提交回复
热议问题