PHP:如何在字符串中查找 * 通配符的出现 [英] PHP: How to find occurrence of a * wildcard character in a string

查看:31
本文介绍了PHP:如何在字符串中查找 * 通配符的出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也许我问的问题有点太平庸了,但我真的不知道如何使用 PHP 检查字符串中是否出现通配符 (*).

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.

示例字符串:*bcd OR ab*d OR abc*

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

无论我尝试使用什么 PHP 函数,它的行为都是不可预测的.我只需要知道通配符是否在字符串中.非常感谢您的回复!

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!

推荐答案

if (strpos($mystring, '*') === false) {
    echo "Wildcard was not found in the string '$mystring'";
} else {
    echo "Wildcard was found in the string '$mystring'";
}

基于 http://php.net/manual/en/function 中的示例.strpos.php

这篇关于PHP:如何在字符串中查找 * 通配符的出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆