使用strpos()搜索针值数组

I'm trying to use strpos to search for some key words in a string using PHP. My question is how would I go about adding a array so I search for "keyword1" and "keyword2" to the code below.

if (strpos($string,'keyword1') !== false) {
$hasstring = "yes";
}

Thanks

If i understand your question correctly, an array is not needed. You can simply use strpos twice with an or (in php, ||) operator

if (strpos($string,'keyword1') || strpos($string,'keyword2')) {
$hasstring = "yes";
}

You can't give strpos an array, so you will have to do it manually.

$keywords = array('keyword1', 'keyword2');

foreach($keywords as $keyword) {
    if (strpos($string, $keyword) !== false) {
        $hasString = true;
        break; // stops searching the rest of the keywords if one was found
    }
}