要检测一个字符串是否以 "lxm_" 开头,你可以使用 PHP 中的字符串函数 strpos()
或正则表达式函数 preg_match()
。
使用 strpos()
函数:
//by www.qzphp.cn $string = "lxm_example"; if (strpos($string, "lxm_") === 0) { echo "字符串以 'lxm_' 开头"; } else { echo "字符串不以 'lxm_' 开头"; }
使用 preg_match()
函数:
//by www.qzphp.cn $string = "lxm_example"; if (preg_match("/^lxm_/", $string)) { echo "字符串以 'lxm_' 开头"; } else { echo "字符串不以 'lxm_' 开头"; }
在这两个示例中,如果字符串以 "lxm_" 开头,将输出 "字符串以 'lxm_' 开头",否则输出 "字符串不以 'lxm_' 开头"。