I need to find one of the three words even if written at the beginning of the string and not just in the middle or at the end. This is my code:
<?php
$string = "one test";
$words = array( 'one', 'two', 'three' );
foreach ( $words as $word ) {
if ( stripos ( $string, $word) ) {
echo 'found<br>';
} else {
echo 'not found<br>';
}
}
?>
If $string is "one test" the search fails; if $string is "test one" the search is good.
Thank you!
striposcan return a value which looks likefalse, but is not, i.e.0. In your second case, the word"one"matches"one test"at position 0 sostriposreturns 0, but in youriftest that is treated as false. Change youriftest toand your code should work fine.