是否有 PHP 通配符布尔过滤器函数


is there a php wildcard boolean filter function

是否有一个 php 函数同时执行通配符过滤和布尔 AND/OR 过滤?

$source = "My dog has fleas";
$filter = "*fleas OR Your*";
echo "Result: ".WildcardBooleanSearch($source, $filter);

结果应该说真或假。在此示例中,它应该说 true。我搜索了网络并找到了通配符过滤,并找到了布尔过滤,但我没有在一个中找到两者。

fnmatch($filter,$source) 处理通配符,但不知道 AND 和 OR 是什么意思。 与preg_match的限制相同。我不能简单地爆炸('或',$filter),因为可能有嵌套的OR和AND。

我能想到的最接近的比较是VBA函数Application.BuildCriteria

使用 PHP preg_match 函数。 如果您使用简单的字符串搜索,也可以使用 strpos。 下面是一个示例:

$source="My dog has fleas";
$filter="fleas or your";
if (strpos($source,$filter)) {
   echo "Found the match";
}

您可以使用preg_match进行更复杂的匹配。

或:

echo "Result: " . preg_match( "/(fleas|Your)/", $source );

和:

echo "Result: " . ( preg_match( "/fleas/", $source ) && preg_match( "/Your/", $source ) );