Jump to content

strpos


searls03

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/257791-strpos/#findComment-1321309
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
https://forums.phpfreaks.com/topic/257791-strpos/#findComment-1323409
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.