我想把一个html文档(X)的一节包含在另一个html文档(Y)中。
这里有:
<div id="cmform">
....
....
</div>在html文档X中,我需要将它包含在html文档Y的div中。我开始阅读PHP文档,并发现了有关"file_get_contents“函数的信息。如果我这样做了:
<?php
$a = file_get_contents("http://site.com/document.html");
echo ($a);
?>我看到了整个页面,我不知道怎么.把范围缩小到那一个分区...
发布于 2013-05-18 04:31:42
您可以在PHP中使用DOMDocument类。
文档:
http://php.net/manual/en/class.domdocument.php
示例:
$documentText = file_get_contents("http://site.com/document.html");
$domDocument = new DOMDocument();
$domDocument->loadHTML( $documentText );
$myDivNode = $domDocument->getElementById( 'the-id-of-the-div' );
$myDivText = $domDocument->saveHTML( $myDivNode );
echo $myDivText;https://stackoverflow.com/questions/16616993
复制相似问题