PHP need to trim all the $_POST variables

前端 未结 8 1878
广开言路
广开言路 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
    }
    

提交回复
热议问题