【发布时间】:2014-10-20 00:15:38
【问题描述】:
我有以下字符串示例:
许多设备不需要维修,他们会尝试等等......
我想查找子字符串是否在此文本中,但使用通配符,如下例所示:
de*es
所以它会找到 "devices" 或其他通配符情况 喜欢
de*
d*v*s
这怎么能用 php 呢?
我尝试使用 fnmatch 函数,但它不起作用!
$txt="many kinds of devices not need repair them and they try etc....";
if (fnmatch("de*es",$text)) { echo "found";} else {exit;}
【问题讨论】:
-
您只能将通配符与正则表达式一起使用 (preg_match())。
-
如何使用 perg_match 做到这一点?
-
如果您阅读 fmatch() 上的文档,您会发现它匹配文件名的方式与通配符在 shell 提示符下的匹配方式完全相同。你需要
fnmatch("*de*es*", ...) -
您的建议对使用 fnmatch 非常有帮助
标签: php string search substring wildcard