是否有一个php通配符布尔过滤器函数

时间:2016-02-01 00:26:33

标签: php string search filter

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

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

结果应该说是真是假。在这个例子中它应该说是真的。 我在网上搜索并发现了通配符过滤,并找到了布尔过滤,但我没有在一个中找到它们。

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

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

2 个答案:

答案 0 :(得分:0)

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

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

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

答案 1 :(得分:0)

或:

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

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