Categories:
.NET (961)
C (387)
C++ (185)
CSS (84)
DBA (8)
General (31)
HTML (48)
Java (641)
JavaScript (220)
JSP (109)
JUnit (31)
MySQL (297)
Networking (10)
Oracle (562)
Perl (48)
Perl (9)
PHP (259)
PL/SQL (140)
RSS (51)
Software QA (28)
SQL Server (5)
Struts (20)
Unix (2)
Windows (3)
XHTML (199)
XML (59)
Other Resources:
What Is the Best Way to Test the strpos() Return Value
What Is the Best Way to Test the strpos() Return Value? - PHP Script Tips - PHP Built-in Functions for Strings
✍: 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.
2007-04-21, 4821👍, 0💬
Popular Posts:
What is XSLT? XSLT is a rule based language used to transform XML documents in to other file formats...
How To Write a Query with a Right Outer Join? - Oracle DBA FAQ - Understanding SQL SELECT Query Stat...
How can you implement MVC pattern in ASP.NET? The main purpose using MVC pattern is to decouple the ...
How To Enter Microseconds in SQL Statements? - MySQL FAQs - Introduction to SQL Date and Time Handli...
What will be printed as the result of the operation below: main() { int x=10, y=15; x = x++; y = ++y...