When I apply a negation !
to preg_match
, I expect the result of the test to be reversed. Yet this doesn't happen.
<?php
$text = '!SPQR! All roads lead to Rome!';
if (!preg_match('!SPQR!', $text) === 0) {echo 'Result A'."<br />";}
else{echo 'Result B'."<br />";}
if (preg_match('!SPQR!', $text) === 0) {echo 'Result A'."<br />";}
else{echo 'Result B'."<br />";}
Output:
Result B
Result B
Why does negation not reverse the outcome?
Manual says:
preg_match() returns 1 if the pattern matches given subject, 0 if it does not, or FALSE if an error occurred.
Manual also says to use ===
to test.
Use the === operator for testing the return value of this function.