strpos($needle,$hey_stack); returns the exact the position of the the needle in the heystack.
The powerful/easy-to-use if(strpos(‘hey’,’hey world’)){//do something}else{//do something else} feature of PHP is also a major weakness if you do not fully understand how if statements in PHP work.
This comes back to a basic programming concept of beginning counting from zero. In the case of strpos(‘hey’,’hey world’) the result is zero.
PHP if statements evaluate the following as false:
false
0
NULL
''
(an empty string)
As strpos(‘hey’,’hey world’); returns zero as ‘hey’ is at string position 0 a simple if statement in PHP would return false.
The correct way is to capture for a real false:
if (strpos('hey', 'hey world')!== false) { //do something } else { //do something else }
Shit*, I gotta re-do a couple of controllers that use this function…