Folks,
Subject today are the VALIDATORS in the function filter_input().
So far, we got these built-into php:
A.
[code]
filter_input(INPUT_POST,”$input”,FILTER_VALIDATE_URL)
B.
[code]
filter_input(INPUT_POST,”$input”,FILTER_VALIDATE_EMAIL)
The above 2 VALIDATORS exist. But not this following one:
[code]
filter_input(INPUT_POST,”$input”,FILTER_VALIDATE_STRING)
Yes, we have the STRING SANITIZER:
[code]
filter_input(INPUT_POST,”$input”,FILTER_SANITIZE_STRING)
But I don’t want to sanitize the user’s (form inputer’s) input. I want to validate it.
So now trying to build my own FILTER_VALIDATE_STRING to use inside the filter_input() function.
I know there are other ways of validating a string but I want to learn how to build my own function or whatever to use it with the filter_input() function. That’s the assignment for now.
The following are my two attempts.
I get the following same error on both.
**Fatal error: Uncaught ArgumentCountError: Too few arguments to function FILTER_VALIDATE_STRING(), 0 passed in C:xampphtdocsTEST.php on line 97 and exactly 1 expected in C:xampphtdocsTemplatesTEST.php:84 Stack trace: #0 C:xampphtdocsTEST.php(97): FILTER_VALIDATE_STRING() #1 {main} thrown in C:xampphtdocsTEST.php on line …
ATTEMPT 1.
[code]
<?php
$input = 123;
function FILTER_VALIDATE_STRING3($data)
{
if(is_string($data))
{
define(“FILTER_VALIDATE_STRING”,”STRING”);
}
else
{
define(“FILTER_VALIDATE_STRING”,”NO STRING”);
}
return $constant(“FILTER_VALIDATE_STRING”);
}
echo FILTER_VALIDATE_STRING();
if(!filter_input(INPUT_POST,”$input”,FILTER_VALIDATE_STRING))
{
die(“Enter a valid STRING!”);
}
?>
ATTEMPT 2.
[code]
<?php
$input = 123;
function FILTER_VALIDATE_STRING($data)
{
if(is_string($data))
{
$constant = define(“FILTER_VALIDATE_STRING”,”STRING”);
}
else
{
$constant = define(“FILTER_VALIDATE_STRING”,”NO STRING”);
}
return $constant(“FILTER_VALIDATE_STRING”);
}
echo FILTER_VALIDATE_STRING();
if(!filter_input(INPUT_POST,”$input”,FILTER_VALIDATE_STRING4))
{
die(“Enter a valid STRING!”);
}
?>
How to rid this problem ?