This has me thrown for a loop:
$s = "ERROR: 5 - [RecordN...blah blah blah";
print stripos($s, 'error') . "\n";
print strpos($s, "ERROR") . "\n";
print $s . "\n";
results in:
0
0
ERROR: 5 - [RecordN...blah blah blah
Huh? All right I’ll try something from here:
$mystring = 'abc';
$findme = 'a';
$pos = strpos($mystring, $findme);
print $pos . "\n";
result is:
0
what?
I’m running:
php --version
PHP 5.3.6-13ubuntu3.6 with Suhosin-Patch (cli) (built: Feb 11 2012 03:26:01)
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
Am I looking at a bug?
Thanks in advance.
EDIT:
Clearly lost my senses there. Thanks for all the responses.
Everything is correct. You are getting zeros because on the first occasion stripos returns 0 as the position of “e” (or “E”), whereas on the second occasion the zero is simply FALSE being printed as an integer.
If you check manual for stripos, you will see that the return value description is
Try changing your code to this and you will see what I mean:
#1, #2 and #4 will be int(0) and #3 will be bool(false).
The exact same thing is happening in your second example. You are checking for position of “a”, which is actually the first character in the string again, which means that its position is 0.
If you need to check if the string is an error you should change your code from (supposedly) this:
to this:
Or make it case sensitive if required: