What is ! in php, if we add it before some function like !preg_match
Here’s the example :
$name = test_input($_POST["name"]);
if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
$nameErr = "Only letters and white space allowed";
}
What is ! in php, if we add it before some function like !preg_match
Here’s the example :
$name = test_input($_POST["name"]);
if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
$nameErr = "Only letters and white space allowed";
}
! means ‘not’.
So the condition is met if the rule returns false
.
To be more precise - not necessarily false
but a falsy value like false, null, 0, empty string or empty array. preg_match
normally returns a number 0 or 1. false
is returned when there is an error (the regex is incorrect).
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.