您可以使用建議的,以更清潔的方式獲得此選項。通過適當使用核心PHP指令和包含,你可以做到這一點,所以你不必觸摸現有的PHP文件在所有!
<?php
// This goes before the page, and this can be done automatically (i.e. without
// modifying the existing PHP file) using auto prepend:
// http://www.php.net/manual/en/ini.core.php#ini.auto-prepend-file
ob_start();
?>
// The "old" page ...
<?php
// This goes after the page, and again can be done automatically using
// auto append (see above).
// This 'if' can also check whether this page is one of those that must be
// manipulated, or not.
if(!isset($_SERVER['EXAMPLE_HEADER']) || ('false'==$_SERVER['EXAMPLE_HEADER']))
{
$html = ob_get_clean();
// Include is only necessary in this scope -- full path may be needed, though
include_once('simple_html_dom.php');
// Here, $html is parsed to yield a DOM object
// ...
foreach($dom->find('div[id=mainContent]') as $div)
{
echo $div->innertext;
}
?>
比我的回答容易得多,效率也更高! – Ricki 2013-02-27 18:18:02