php 警告:preg_match() [function.preg-match]:未知修饰符“/”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3327848/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 09:21:13  来源:igfitidea点击:

Warning: preg_match() [function.preg-match]: Unknown modifier '/'

phppreg-match

提问by ron8

I'm trying to use preg_match to return all the URL's that are inclosed in " " in a page source code.

我正在尝试使用 preg_match 返回页面源代码中包含在“”中的所有 URL。

The code I am using is

我使用的代码是

preg_match('"http://(.+?)\"', $code, $matches);

And I am getting the following error:

我收到以下错误:

Warning: preg_match() [function.preg-match]: Unknown modifier '/' in .... on line 13

回答by Jim W.

preg_match('~"http://(.*)"~iU', $code, $matches);

Your issue was you need delimiters (I chose ~) to use with the pattern. See the preg_match()man page for more information.

您的问题是您需要分隔符(我选择了 ~)来与模式一起使用。有关更多信息,请参阅preg_match()手册页。

回答by ron8

Try this:

尝试这个:

preg_match('"http:\/\/(.+?)\"', $code, $matches);