I think my understanding of comparison operators and boolean results is dodgy.
Basically I have a variable $foo in which is the string "trade magazines", or "consumer magazines"
I'm trying to have an if statement which detects whether the word "trade" is in $foo
According to the PHP documentation strpos() is the way to do this as it is less memory intensive than strstr()
I've successfully got an if statement working to check if the word "trade" isn't in $foo using === false
But how do I write the if statement to detect if "trade" is in $foo?
I've already tried the following...
Code: Select all
1) if (strpos($foo, "trade") > 0)
2) if (strpos($foo, "trade") <> false)
3) if (strpos($foo, "trade") !== false
4) if (strpos($foo, "trade") != false)If any of the above are correct then let me know as it may be something else in my code throwing out the error.
What's the correct syntax to do this?
Using <> I think is incorrect as it's an arithmatic operator.
I would have thought either !== or != would work, being comparison operators but they don't seem to be.
If any of the above are correct then let me know as I'll try and track something else down in my code.
If anyone could explain how to deal with the results of functions that can either return false, or a number then let me know too so I can learn a bit more.
Thanks