我使用Dom解析器从body标签中的html页面中提取内容,如:
$html = file_get_contents('index.php');
libxml_use_internal_errors(true);
$dom = new DOMDocument();
$dom->loadHTML($html);
$body = "";
foreach($dom->getElementsByTagName("body")->item(0)->childNodes as $child) {
$body .= $dom->saveHTML($child);
}
echo $body;
但现在我需要将修改后的$ body变量放回index.php文件并替换tag中的内容。我可以使用file_put_contents()