Tools, FAQ, Tutorials:
Testing the strpos() Return Value in PHP
What Is the Best Way to Test the strpos() Return Value?
✍: FYIcenter.com
Because strpos() could two types of values, Integer and Boolean, you need to be careful about testing the return value. The best way is to use the "Identical(===)" operator. Do not use the "Equal(==)" operator, because it does not differentiate "0" and "false". Check out this PHP script on how to use strpos():
<?php
$haystack = "needle234953413434516504381640386488129";
$pos = strpos($haystack, "needle");
if ($pos==false) {
print("Not found based (==) test\n");
} else {
print("Found based (==) test\n");
}
if ($pos===false) {
print("Not found based (===) test\n");
} else {
print("Found based (===) test\n");
}
?>
This script will print:
Not found based (==) test Found based (===) test
Of course, (===) test is correct.
2016-10-13, ∼3548🔥, 0💬
Popular Posts:
How to build a PHP script to dump Azure AD 2.0 Authentication Response? If you are use the Azure-AD-...
How to add request query string Parameters to my Azure API operation to make it more user friendly? ...
How to use "{{...}}" Liquid Codes in "set-body" Policy Statement? The "{{...}}" Liquid Codes in "set...
How To Get the Minimum or Maximum Value of an Array in PHP? If you want to get the minimum or maximu...
Where can I download the EPUB 2.0 sample book "The Metamorphosis" by Franz Kafka? You can following ...