Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.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 用正则表达式匹配两个标记之间的所有内容?_Php_Html_Regex_Tags - Fatal编程技术网

Php 用正则表达式匹配两个标记之间的所有内容?

Php 用正则表达式匹配两个标记之间的所有内容?,php,html,regex,tags,Php,Html,Regex,Tags,如何匹配(PCRE)两个标记之间的所有内容 我试过这样的方法: (**) 但这对我来说不是很好 我对正则表达式有点陌生,所以我希望有人能向我解释一下,如果正则表达式可能的话,我将如何实现这一点 谢谢PHP和正则表达式?以下是一些建议: '/<!--\s*LoginStart\s*-->(.*)<!--\s*LoginEnd\s*-->/Us' “/(.*)/Us” 可能更好-大写的U使正则表达式不贪婪,这意味着它将在第一个$string='text'处停止; $reg

如何匹配(PCRE)两个标记之间的所有内容

我试过这样的方法:

(**)

但这对我来说不是很好

我对正则表达式有点陌生,所以我希望有人能向我解释一下,如果正则表达式可能的话,我将如何实现这一点


谢谢

PHP和正则表达式?以下是一些建议:

'/<!--\s*LoginStart\s*-->(.*)<!--\s*LoginEnd\s*-->/Us'
“/(.*)/Us”
可能更好-大写的
U使正则表达式不贪婪,这意味着它将在第一个
$string='text'处停止;
$regex='#(.*)#s';
preg_match($regex,$string,$matches);
打印($matches);//$匹配[1]=文本
说明:

(.*?) = non greedy match (match the first <!-- LoginEnds --> it finds
    s = modifier in $regex (end of the variable) allows multiline matches
        such as '<!-- LoginStart -->stuff
                 more stuff
                 <!-- LoginEnds -->'
(.*)=非贪婪匹配(匹配它找到的第一个
$regex(变量末尾)中的s=修饰符允许多行匹配
比如“东西”
更多的东西
'

我试过欧文的答案,但在以下情况下失败了

text“别介意”文本

这也包括“别介意”这一行,也就是说它涵盖了第一节中的所有内容 最后一个标签是什么

(.*?) = non greedy match (match the first <!-- LoginEnds --> it finds
    s = modifier in $regex (end of the variable) allows multiline matches
        such as '<!-- LoginStart -->stuff
                 more stuff
                 <!-- LoginEnds -->'