PHP 5.2 preg_match() 编译失败
非常感谢一些帮助。我的主机服务器端更新导致我的评论表单抛出两个验证错误。第一个是: preg_match() 返回警告:preg_match() [function.preg-match]:编译失败:[脚本位置和行错误]中偏移量 13 处字符类中的范围无序 - 第二个是主题检查偏移量 14。
它在电子邮件地址检查:
if (preg_match('/[^a-zA-Z0-9_-.]/', $_POST['txtEmail']))
和主题检查:
if (preg_match('/[^a-zA-Z0-9:?-. ]/', $_POST['txtSubject']))
我不熟悉 PHP,但可以剪切和粘贴!我的网站是 frowey.com,在托管操作系统更新后,联系我们的评论表单开始抛出错误。提前致谢。
Would very much appreciate some help. My hosts server-side updates have caused my comment form to throw two validation errors. First one is: preg_match() returns Warning: preg_match() [function.preg-match]: Compilation failed: range out of order in character class at offset 13 in [script location here and line error] - second is on subject check at offset 14.
It does this on the email address check:
if (preg_match('/[^a-zA-Z0-9_-.]/', $_POST['txtEmail']))
and subject check:
if (preg_match('/[^a-zA-Z0-9:?-. ]/', $_POST['txtSubject']))
I'm not familiar with PHP but can cut and paste! My website's frowey.com and it's the comments form on contact us that's started throwing an error after hosting OS updates. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要转义
-
减号。正如错误消息所提示的那样,它对于字符类具有特殊含义。在减号之前使用反斜杠:(或者
-
可能是字符组中的第一个或最后一个,因此它失去了其特殊功能。)You need to escape the
-
minus. It has special meaning with character classes, as the error message hints. Use a backslash before the minus:(Alternatively the
-
may be the first or last thing in the character group, so it loses its special function.)