I found this, when I'm working in regex validation in PHP.
I've used preg_match
function to validate a string.
I've just printed that value returned by preg_match
to ensure working flow.
During that I've found a thing. But can't understand their concept.
That was preg_match()
returns 1 if the match found. Otherwise, it will return 0. But sometimes my print function didn't print anything.
After I went through the PHP manual to know all of its return value...
There they posted as follows...
preg_match() returns 1 if the pattern matches given subject, 0 if it does not, or FALSE if an error occurred.
And then I used var_dump
to know anything is printed or not...
This helped me to know that's a Boolean false.
But I'm curious to know why it returns boolean false, when I'm just putting " ! " (not) before the preg_match()
?
Following is my code,
echo preg_match("/script/", "script") // ===> this returns 1
echo !preg_match("/script/", "script") // ===> this returns Boolean false
I think it has to return integer 0 (zero)... What is its functionality? Or did I do anything wrong in syntax?
I've tried this in the OpenCart 2.0.0.0 system administrator controller module.