如何删除标记内容

时间:2016-03-11 14:13:56

标签: php

我已更改$content = " <html> <head> <title>test</title> </head> <body> <div class='param1'>Some text 1 <p>:)</p></div> <div class='param2'>Some text 2</div> </body> </html> "; 并在此更改html代码中保存另一个网站。 例如:

==

我怎么能用这个div的所有内容来销毁标签?

谢谢。

1 个答案:

答案 0 :(得分:2)

我认为这就是你所追求的:

$content = "
    <html>
       <head>
           <title>test</title>
       </head>
       <body>
           <div class='param1'>Some text 1 <p>:)</p></div>
           <div class='param2'>Some text 2</div>
       </body>
    </html>
";

$pattern = "/<div class='param1'>.*<\/div>/";
$content = preg_replace($pattern, '', $content);

header('Content-type: text/plain');
echo $content;

<强>输出

<html>
   <head>
       <title>test</title>
   </head>
   <body>

       <div class='param2'>Some text 2</div>
   </body>
</html>
相关问题