crusty76 Posted May 6, 2010 Share Posted May 6, 2010 I thought it would be simple but it isn't. I have the code (example) <?PHP $search="a"; $total = "aNbh jK "; if( stripos(" " .$total,$search,0) == TRUE) { echo"found"; } else { echo "Not found"; } ?> The result is 'Not found'. It should be found surely? If $search ="n" it works.! What am I doing wrong please. Crusty Link to comment https://forums.phpfreaks.com/topic/200894-help-with-stripos/ Share on other sites More sharing options...
litebearer Posted May 6, 2010 Share Posted May 6, 2010 I think using === (3 equal signs) will cure that, it has to do with false and 0 (zero) which is the pos of first character, somehow eqauting to same when you use 2 equals signs Link to comment https://forums.phpfreaks.com/topic/200894-help-with-stripos/#findComment-1054142 Share on other sites More sharing options...
crusty76 Posted May 6, 2010 Author Share Posted May 6, 2010 Thanks for the suggestion. Tried that and unfortunately, it doesn't work. Seems it wont find a character which is the first character in '$haystack' In my case $total. Any other thoughts please. I'm getting frustrated with thus simple(?) problem. Thanks Crusty <?PHP $search="a"; $total = "aNbh jK "; if( stripos(" " .$total,$search,0) === TRUE) { echo"found"; } else { echo "Not found"; } ?> Link to comment https://forums.phpfreaks.com/topic/200894-help-with-stripos/#findComment-1054162 Share on other sites More sharing options...
siric Posted May 6, 2010 Share Posted May 6, 2010 Tried it and works for me. Link to comment https://forums.phpfreaks.com/topic/200894-help-with-stripos/#findComment-1054169 Share on other sites More sharing options...
mattal999 Posted May 6, 2010 Share Posted May 6, 2010 <?php $search = "a"; $total = "aNbh jK "; if(stripos(" ".$total, $search) !== false) { // Manual states using 3 signs, and it will not return true if found, but instead a number. echo "Found"; } else { echo "Not found"; } ?> Link to comment https://forums.phpfreaks.com/topic/200894-help-with-stripos/#findComment-1054173 Share on other sites More sharing options...
litebearer Posted May 6, 2010 Share Posted May 6, 2010 quote from the manual... Warning This function may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE, such as 0 or "". Please read the section on Booleans for more information. Use the === operator for testing the return value of this function. http://php.net/manual/en/function.stripos.php might try using >=0 rather than 'true/false' Link to comment https://forums.phpfreaks.com/topic/200894-help-with-stripos/#findComment-1054188 Share on other sites More sharing options...
crusty76 Posted May 6, 2010 Author Share Posted May 6, 2010 Thanks everyone.... using if( stripos($total,$search,0) !== FALSE) Seems to work. Much obliged.. Crusty Link to comment https://forums.phpfreaks.com/topic/200894-help-with-stripos/#findComment-1054193 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.