PHP: How to find occurrence of a * wildcard charac

2020-05-09 12:26发布

Maybe I'm asking a bit too banal question, but I really cannot figure out how to check for an occurrence of a wildcard (*) character in a string using PHP.

An example string: *bcd OR ab*d OR abc*

Whatever PHP function I try to use, it behaves unpredictably. I just need to know whether the wildcard character is or is not in a string. Thank you very much for replies!

1条回答
Animai°情兽
2楼-- · 2020-05-09 13:00
if (strpos($mystring, '*') === false) {
    echo "Wildcard was not found in the string '$mystring'";
} else {
    echo "Wildcard was found in the string '$mystring'";
}

Based on the example at http://php.net/manual/en/function.strpos.php

查看更多
登录 后发表回答