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, 2487👍, 0💬
Popular Posts:
Can Two Forms Be Nested? Can two forms be nested? The answer is no and yes: No. You can not nest two...
How to troubleshoot the Orderer peer? The Docker container terminated by itself. You can follow this...
Where Is the Submitted Form Data Stored in PHP? When a user submit a form on your Web server, user e...
Can Multiple Paragraphs Be Included in a List Item? Yes. You can include multiple paragraphs in a si...
How to convert a JSON text string to an XML document with PHP language? Currently, there is no built...