What exactly does the PHP function “test_input()” do?

前端 未结 4 630
夕颜
夕颜 2021-02-04 11:01

I know I will be voted down for this, but I need to ask. What does the code below mean? Specifically, I am confused by

if (empty($_POST[\"comment\"])) { $comme         


        
4条回答
  •  再見小時候
    2021-02-04 11:29

    test_input() is a user - defined function used by w3schools:

    function test_input($data) {
        $data = trim($data);
        $data = stripslashes($data);
        $data = htmlspecialchars($data);
        return $data;
    }
    

    For example:

    
    
    • trim($data) will strip unnecessary characters (extra space, tab, newline) from the user input data (with the PHP trim() function).
    • stripslashes($data) will remove backslashes () from the user input data (with the PHP stripslashes() function).
    • htmlspecialchars($data) converts special characters to HTML entities.
      • (If the user inputs < and >, htmlspecialchars() will translate it to < and >).

提交回复
热议问题