【发布时间】:2011-02-28 03:19:18
【问题描述】:
我正在尝试将 div 'resultsContainer' 中的 html 代码替换为 $response 的 html。
我的代码不成功的结果是“resultsContainer”的内容仍然存在,并且 $response 的 html 在屏幕上显示为文本而不是被解析为 html。
最后,我想在 'resultContainer' 中注入 $response 的内容,而不必创建任何新的 div,我需要这个:<div id='resultsContainer'>Html inside $response here...</div> 而不是这个:<div id='resultsContainer'><div>Html inside $response here...</div></div>
// Set Config
libxml_use_internal_errors(true);
$doc = new DomDocument();
$doc->strictErrorChecking = false;
$doc->validateOnParse = true;
// load the html page
$app = file_get_contents('index.php');
$doc->loadHTML($app);
// get the dynamic content
$response = file_get_contents('search.php'.$query);
$response = utf8_decode($response);
// add dynamic content to corresponding div
$node = $doc->createElement('div', $response);
$doc->getElementById('resultsContainer')->appendChild($node);
// echo html snapshot
echo $doc->saveHTML();
【问题讨论】: