Php 在自定义注释之间获取内容

Php 在自定义注释之间获取内容,php,regex,preg-match,Php,Regex,Preg Match,我有一个html字符串。在这一点上,我定义了一些编辑区域。该区域包含在某些注释中。我想得到评论之间的所有内容。比如说 <!--start--> some content with any html tag <!--end--> 带有任何html标记的某些内容 在上面的示例中,我需要开始和结束标记之间的内容。这就是我们的需求 带有任何html标记的某些内容 -Arun$string='some content with any html tag'; preg_match

我有一个html字符串。在这一点上,我定义了一些编辑区域。该区域包含在某些注释中。我想得到评论之间的所有内容。比如说

<!--start--> some content with any html tag <!--end-->
带有任何html标记的某些内容
在上面的示例中,我需要开始和结束标记之间的内容。这就是我们的需求

带有任何html标记的某些内容

-Arun

$string='some content with any html tag';
preg_match(“/(.*?/”,$string,$matches);
var_dump($matches);
$string='some content with any html tag';
preg_match(“/(.*?/”,$string,$matches);
var_dump($matches);
$string='some content with any html tag';
echo preg_替换(“/(.*)/”、“$1”和$string);
$string='some content with any html tag';
echo preg_替换(“/(.*)/”、“$1”和$string);

它会抛出一个错误。未知修饰符'@user504383:对我有效:。你在用php5吗?Sorry danilo,你的帖子很有效。hsz代码出错。再次抱歉并感谢您的帮助,请参阅我对hsz回答的评论。它抛出了一个错误。未知修饰符'@user504383:对我有效:。你在用php5吗?Sorry danilo,你的帖子很有效。hsz代码出错。再次抱歉并感谢您的帮助,请参阅我对hsz答案的评论更好,请不要发布未经测试的答案。有了这样的在线测试人员,就没有理由了。当有一行内容时,代码就不起作用了。例如$string=“head some content with any html tag”;请尝试此示例您可能需要
s
修饰符(PCRE_DOTALL)以便
preg_匹配('/(.*)/s',$string,$matches)
$matches[1]
中提供了您想要的内容,甚至更好,请不要发布未经测试的答案。有了这样的在线测试人员,就没有理由了。当有一行内容时,代码就不起作用了。例如$string=“head some content with any html tag”;请尝试此示例您可能需要
s
修饰符(PCRE_DOTALL)以便
preg_匹配('/(.*)/s',$string,$matches)
$matches[1]
$string = '<!--start--> some content with any html tag <!--end-->';
preg_match('/<!--start-->(.*?)<!--end-->/', $string, $matches);

var_dump($matches);
$string = '<!--start--> some content with any html tag <!--end-->';
echo preg_replace('/<!--start--> (.*) <!--end-->/', '$1', $string);