Jump to content



Recommended Posts

How do I do two strpos conditions?  here is kinda what I have....


if (strpos($val,'Sparring') && ($val,'Ecas') {





You can have two instances of strpos in one if for example...


$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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.