Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/254.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PHP中检查字符串是否出现多个值_Php_String - Fatal编程技术网

在PHP中检查字符串是否出现多个值

在PHP中检查字符串是否出现多个值,php,string,Php,String,我正在对检索到的传记字符串进行检查,以确定艺术家是否仍处于活动状态 生物样本: $bio = 'Band was a psychedelic/progressive rock band'; 目前我有 $active = (strpos($bio, 'was an')) ? false : true; 但我还要检查其他事件。 比如: 有没有一种不使用循环的简单方法?因此,如果bio字符串包含非活动数组中的任何值,则返回false。尝试此正则表达式方法: if(preg_match('~(was

我正在对检索到的传记字符串进行检查,以确定艺术家是否仍处于活动状态

生物样本:

$bio = 'Band was a psychedelic/progressive rock band';
目前我有

$active = (strpos($bio, 'was an')) ? false : true;
但我还要检查其他事件。 比如:


有没有一种不使用循环的简单方法?因此,如果bio字符串包含非活动数组中的任何值,则返回false。

尝试此正则表达式方法:

if(preg_match('~(was a|was an|died|were a|were an)~', $input)) {
    echo 'not active anymore';
}
或简化:

if(preg_match('~(was an?|died|were an?)~', $input)) {
    echo 'not active anymore';
}

尝试这种正则表达式方法:

if(preg_match('~(was a|was an|died|were a|were an)~', $input)) {
    echo 'not active anymore';
}
或简化:

if(preg_match('~(was an?|died|were an?)~', $input)) {
    echo 'not active anymore';
}
有些相似;有些相似;