“未知修饰符 'g' in..."在 PHP 中使用 preg_match 时? [英] "Unknown modifier 'g' in..." when using preg_match in PHP?
本文介绍了“未知修饰符 'g' in..."在 PHP 中使用 preg_match 时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我尝试使用的正则表达式:
This is the regex I'm trying to use:
/^(w|.|-)+?@(w|-)+?.w{2,4}($|.w{2,4})$/gim
我在本网站上找到了它,当我在那里试用时效果很好.但是一旦我把它放在我的代码中,我就会收到这条消息:
I found it on this site, and it works great when I try it out there. But as soon as I place it in my code, I get this message:
Warning: preg_match() [function.preg-match]: Unknown modifier 'g' in C:xampphtdocsswebookincludesclasses.php on line 22
谁能解释一下出了什么问题,为什么它可以在该网站上而不是在我的代码中运行?
Can anyone explain what's wrong, and why it's working on that website and not in my code?
推荐答案
g>preg_match
.相反,您必须使用 preg_match_all
函数.
所以代替:
preg_match("/^(w|.|-)+?@(w|-)+?.w{2,4}($|.w{2,4})$/gim", ....)
使用:
preg_match_all("/^(w|.|-)+?@(w|-)+?.w{2,4}($|.w{2,4})$/im", ....)
这篇关于“未知修饰符 'g' in..."在 PHP 中使用 preg_match 时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文