<?php
class validation {
function clean_txt($str, $letter_case="") {
trim($str);
filter_var($str, FILTER_SANITIZE_STRING);
switch ($letter_case) {
case "L":
strtolower($str);
break;
case "U":
strtoupper($str);
break;
case "T":
ucwords($str);
break;
default:
$str="";
}
return ($str);
}
function clean_email($email_var) {
filter_var($email_var, FILTER_SANITIZE_EMAIL);
return ($email_var);
}
function clean_int($int_var) {
trim($int_var);
filter_var($int_var, FILTER_SANITIZE_NUMBER_INT);
return ($int_var);
}
$functions = new validation();
$var = $functions->clean_txt(" Hello, HOw Are you?", "L");
echo $var;
?>
<br>
<?php
$var = $functions->clean_email(":zsdazey@gmail.com");
echo $var;
?>
<br>
<?php
$var = $functions->clean_int("38u");
echo $var;
?>
It returns:
Hello, HOw Are you?
:email@gmail.com
38u
It SHOULD be returning:
hello, how are you?
email@gmail.com
38
Does anyone see what I'm missing here? I know the methods are at least passing the variables through, and the trim()
function is working just fine.