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, 3174🔥, 0💬
Popular Posts:
How To Open Standard Output as a File Handle in PHP? If you want to open the standard output as a fi...
What Is session_register() in PHP? session_register() is old function that registers global variable...
How To Pad an Array with the Same Value Multiple Times in PHP? If you want to add the same value mul...
How to access Request body from "context.Request.Body" object in Azure API Policy? Request body is t...
Where to find tutorials on RSS specifications? I want to learn it to describe my API services. Here ...