niche Posted April 6, 2018 Share Posted April 6, 2018 (edited) $haystack = ",18,19,42,"; $needle = ",18,"; if (strpos($haystack,$needle)) { echo 'TRUE'; } else { echo 'FALSE'; } This returns FALSE. What am I missing? Edited April 6, 2018 by niche Link to comment Share on other sites More sharing options...
dsonesuk Posted April 6, 2018 Share Posted April 6, 2018 The problem is in the function name 'strpos' being at the beginning, the position will be 0, so 0 will be treated as false. The position of needle text placed anywhere but the beginning will be greater than 0, meaning true. You need to check against not being false within the if condition and make sure you use !== compared to != with single equals symbol. http://php.net/manual/en/function.strpos.php 1 Link to comment Share on other sites More sharing options...
davej Posted April 6, 2018 Share Posted April 6, 2018 Accidentally using truthiness... Link to comment Share on other sites More sharing options...
niche Posted April 6, 2018 Author Share Posted April 6, 2018 thanks dsonesuk! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now