sanitize php input code example
Example 1: sanitize form data php
function clean($data)
{
$data = htmlspecialchars($data);
$data = stripslashes($data);
$data = trim($data);
return $data;
}
Example 2: sanitize user input php
<?php
function sanitize($string) {
return addslashes(htmlspecialchars($string));
}
?>
Example 3: php clean user input
<?php
function cleanUserInput($userinput) {
$dbConnection = databaseConnect();
if (empty($userinput)) {
return;
} else {
$userinput = htmlspecialchars($userinput);
$userinput = mysqli_real_escape_string($dbConnection, $userinput);
}
return $userinput;
}
?>