Never trust user data.
function clean_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
The trim()
function removes whitespace and other predefined characters from both sides of a string.
The stripslashes()
function removes backslashes
The htmlspecialchars()
function converts some predefined characters to HTML entities.
The predefined characters are:
& (ampersand) becomes &
" (double quote) becomes "
' (single quote) becomes '
< (less than) becomes <
> (greater than) becomes >