preg_match(): 未知修饰符 '/' [英] preg_match(): Unknown modifier '/'

查看:49
本文介绍了preg_match(): 未知修饰符 '/'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我用这个正则表达式来验证 URL 时,它显示错误...

When i give this regular expression for validating URL it shows error...

preg_match(): C:\wamp64\www\php\Form 中的未知修饰符 '/'Validation\form.php 第 36 行

preg_match(): Unknown modifier '/' in C:\wamp64\www\php\Form Validation\form.php on line 36

if(!preg_match("/%^(?:(?:https?|ftp)://)(?:\S+(?::\S*)?@|\d{1,3}(?:\.\d{1,3}){3}|(?:(?:[a-z\d\x{00a1}-\x{ffff}]+-?)*[a-z\d\x{00a1}-\x{ffff}]+)(?:\.(?:[a-z\d\x{00a1}-\x{ffff}]+-?)*[a-z\d\x{00a1}-\x{ffff}]+)*(?:\.[a-z\x{00a1}-\x{ffff}]{2,6}))(?::\d+)?(?:[^\s]*)?$%iu/",$website)){
            $websiteerror="Invalid URL";

推荐答案

由于您使用正斜杠 / 作为分隔符,因此您必须在正则表达式中对其进行转义:

Since you used forward slash / as the delimiter, you must escape it inside the regex:

if (!preg_match("/%^(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@|\d{1,3}(?:\.\d{1,3}){3}|(?:(?:[a-z\d\x{00a1}-\x{ffff}]+-?)*[a-z\d\x{00a1}-\x{ffff}]+)(?:\.(?:[a-z\d\x{00a1}-\x{ffff}]+-?)*[a-z\d\x{00a1}-\x{ffff}]+)*(?:\.[a-z\x{00a1}-\x{ffff}]{2,6}))(?::\d+)?(?:[^\s]*)?$%iu/",$website)) {
    $websiteerror = "Invalid URL";
}

现在代码为我运行,但我仍然收到此警告:

Now the code runs for me, but I still get this warning:

PHP 警告:preg_match():编译失败:\x{} 或 \o{} 中的字符值在第 3 行 source_file.php 中的偏移量 106 处太大

PHP Warning: preg_match(): Compilation failed: character value in \x{} or \o{} is too large at offset 106 in source_file.php on line 3

PHP 似乎并不完全喜欢您在某些字符类中使用的十六进制范围.

It seems PHP doesn't completely like the hex ranges you used in some of your character classes.

这篇关于preg_match(): 未知修饰符 '/'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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