PHP:查找HTML标签之间的内容


PHP : Find contents between a HTML TAG

我的HTML看起来像这样,我得到它在一个PHP字符串$输出,我需要做的是分割字符串,只显示<!-- start Default Content //--> AND <!-- end Default Content //-->

之间的内容
<html> 
    <head> 
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
        <title>Multimedia Message</title> 
    </head> 
    <body leftmargin="0" topmargin="0"> 

                <tr height="15" style="border-top: 1px solid #0F7BBC;"> 
                    <td> 
                        <!-- start Default Content //-->
sdf sdf

sd fsd
<br> </br>
s
df
sd
f 
s
<!-- end Default Content //-->
                    </td> 
                </tr> 

     </body> 
</html> 

一个解决方案是使用正则表达式:

$matches = array();
preg_match("#<!-- start Default Content //-->(.*)<!-- end Default Content //-->#isu", $html, $matches);
echo $matches[1];

应该可以了

preg_match ('/Start Default Content '/'/-->.*<!-- end Default Content/',$output,$matches);
    $string = substr($matches[0],27,-24);