我有更改$content
,我在此更改 html 代码中保存另一个站点。例如:
$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>
";
我怎样才能销毁包含此div所有内容的标签?
谢谢。
我认为这就是你所追求的:
$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>