我想将test.php(包含文件)的html结构转换为index.php。这就是我到目前为止所做的......
/ * index.php * /
<?php
$url = basename($_SERVER['REQUEST_URI'], '?'.$_SERVER['QUERY_STRING']);
$html = file_get_contents($url);
$d = new DOMDocument('1.0');
$d->formatOutput = true;
$d->loadHTML($html);
$x = new DOMXPath($d);
foreach ($x->query('//*[text()[contains(., "!TEXT")]]') as $node) {
if(!empty($node->nodeValue)){
/////
}
}
echo $d->saveHTML();
?>
/////////////////////////////////////////////// /////////
/ * test.php * /
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<p>sample</p>
<?php include('inc.php'); ?>
</body>
</html>
////////////////////////////////////////
我一直在得到这个结果(在DOM Inspector中)
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
</head>
<body>
<p>sample</p>
<!--?php include('inc.php'); ?-->
</body></html>