"...中的未知修饰符'g'".在PHP中使用preg_match时? [英] "Unknown modifier 'g' in..." when using preg_match in PHP?

查看:93
本文介绍了"...中的未知修饰符'g'".在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:\xampp\htdocs\swebook\includes\classes.php on line 22

任何人都可以解释出什么问题了,为什么它可以在该网站上运行,而不是在我的代码中?

Can anyone explain what's wrong, and why it's working on that website and not in my code?

推荐答案

对于 preg_match .相反,您必须使用 preg_match_all 函数.

There is no modifier g for preg_match. Instead, you have to use the preg_match_all function.

所以代替:

preg_match("/^(\w|\.|-)+?@(\w|-)+?\.\w{2,4}($|\.\w{2,4})$/gim", ....)

使用:

preg_match_all("/^(\w|\.|-)+?@(\w|-)+?\.\w{2,4}($|\.\w{2,4})$/im", ....)

这篇关于"...中的未知修饰符'g'".在PHP中使用preg_match时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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