Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 为什么preg#u match不';当正则表达式正常时,在标记之间找不到字符串?_Php_Html_Regex_Preg Match_Preg Match All - Fatal编程技术网

Php 为什么preg#u match不';当正则表达式正常时,在标记之间找不到字符串?

Php 为什么preg#u match不';当正则表达式正常时,在标记之间找不到字符串?,php,html,regex,preg-match,preg-match-all,Php,Html,Regex,Preg Match,Preg Match All,我这里有下一个问题。我试图用preg_match/preg_match_all在两个HTML注释标记之间获取一个字符串,但得到的结果是一个包含大量记录的空数组 这是我的密码: $pattern = "/\<!-- Start of NewsTicker --\>(.*)\<!-- End of NewsTicker --\>/"; preg_match_all($pattern, $description , $matches); $pattern=“/\是否尝试转义反

我这里有下一个问题。我试图用preg_match/preg_match_all在两个HTML注释标记之间获取一个字符串,但得到的结果是一个包含大量记录的空数组

这是我的密码:

$pattern = "/\<!-- Start of NewsTicker --\>(.*)\<!-- End of NewsTicker --\>/";
preg_match_all($pattern, $description , $matches);

$pattern=“/\是否尝试转义反斜杠和其他特殊字符?另外,处理预格式化文本或正则表达式时通常最好使用单引号

像这样:

$pattern = '/\\<\!-- Start of NewsTicker --\\>(.*)\\<\!-- End of NewsTicker --\\>/'
preg_match_all($pattern, $description , $matches);
$pattern='/\\(.*)\\/'
preg_match_all($pattern,$description,$matches);
还有帮助:

您应该添加“匹配换行符”标志,即
s

因此,您的正则表达式应该如下所示:

$pattern = "/\<!-- Start of NewsTicker --\>(.*)\<!-- End of NewsTicker--\>/s";

$pattern=“/\n尝试此正则表达式
(?s)
您需要在regexpOh中使用
s
标志,非常感谢它确实有效。老实说,我甚至不知道正则表达式模式中的“.”不包括换行符。