匹配字符串与shell样式的通配符(例如,*)

xvi*_*ilo 5 php string wildcard

是否可以在if语句中使用通配符?

我的代码:

* =通配符

if ($admin =='*@some.text.here') {

}
Run Code Online (Sandbox Code Playgroud)

$admin 将是以下之一:

  • xvilo@some.text.here
  • bot!bot@some.text.here
  • lakjsdflkjasdflkj@some.text.here

Wis*_*guy 14

如果您不想使用正则表达式,fnmatch()可能会为此[有限]目的服务.它使用像您期望的类似shell的通配符来匹配字符串.

if (fnmatch('*@some.text.here', $admin)) {

}
Run Code Online (Sandbox Code Playgroud)