searls03 Posted February 26, 2012 Share Posted February 26, 2012 How do I do two strpos conditions? here is kinda what I have.... if (strpos($val,'Sparring') && ($val,'Ecas') { } Quote Link to comment https://forums.phpfreaks.com/topic/257791-strpos/ Share on other sites More sharing options...
blacknight Posted February 26, 2012 Share Posted February 26, 2012 http://php.net/manual/en/function.strpos.php rtfm ftw? Quote Link to comment https://forums.phpfreaks.com/topic/257791-strpos/#findComment-1321304 Share on other sites More sharing options...
searls03 Posted February 26, 2012 Author Share Posted February 26, 2012 I did read the manual and I couldn't find what I wanted. Quote Link to comment https://forums.phpfreaks.com/topic/257791-strpos/#findComment-1321305 Share on other sites More sharing options...
blacknight Posted February 26, 2012 Share Posted February 26, 2012 what is it you are trying to do exactly maybe this is the wrong function Quote Link to comment https://forums.phpfreaks.com/topic/257791-strpos/#findComment-1321306 Share on other sites More sharing options...
Anon-e-mouse Posted February 26, 2012 Share Posted February 26, 2012 How do I do two strpos conditions? here is kinda what I have.... if (strpos($val,'Sparring') && ($val,'Ecas') { } Morning, You can have two instances of strpos in one if for example... <?php $a = 'abcde'; $b = 'abcde'; if(strpos($a, 'a') && strpos($b, 'a')){ echo "Yes"; } else { echo "No"; } ?> That will echo out "Yes", because strpos found "a" in both of the strings $a and $b. Equally you could choose to ask for different needles in each strpos because they are essentially separate. If you fancied going for either or the result you were looking for with the strpos you could use the operator: "||" in the place of "&&" which will allow either or the results to be positive opposed to needing both to return correct. Hope it helps. Quote Link to comment https://forums.phpfreaks.com/topic/257791-strpos/#findComment-1321309 Share on other sites More sharing options...
searls03 Posted March 3, 2012 Author Share Posted March 3, 2012 how would I do something like this? <?php } else if(strpos($val, 'Sparring') && strpos($val, 'head') == true){ ?> this doesn't return what would be inside it, but rather the last else condition....I need to be the same string it is pulling from, but looking to make sure two words are contained in it. Quote Link to comment https://forums.phpfreaks.com/topic/257791-strpos/#findComment-1323409 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.