Tony Roc
Tony Roc

Reputation: 1

PHP: How to find occurrence of a * wildcard character in a string

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!

Upvotes: 0

Views: 1271

Answers (1)

Adam Westbrook
Adam Westbrook

Reputation: 1113

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

Upvotes: 4

Related Questions