sanitize user input php 1

sanitize user input php

# sanitize form data
function clean($data)
    $data = htmlspecialchars($data);
    $data = stripslashes($data);
    $data = trim($data);
    return $data;

Here is what the above code is Doing:
1. We’re creating a function called clean() that takes in a string as a parameter.
2. We’re using the PHP htmlspecialchars() function to convert special characters to HTML entities.
3. We’re using the PHP stripslashes() function to remove backslashes.
4. We’re using the PHP trim() function to remove whitespace from the beginning and end of the string.
5. We’re returning the cleaned data.

Similar Posts