php cleaning user input code example
Example 1: how to request user input in php
<?php
echo "What do you want to input? ";
$input = rtrim(fgets(STDIN));
echo "I got it:\n" . $input;
Example 2: sanitize form data php
function clean($data)
{
$data = htmlspecialchars($data);
$data = stripslashes($data);
$data = trim($data);
return $data;
}
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;
}
?>