childNodes;
foreach ($children as $child) {
$innerHTML .= $child->ownerDocument->saveXML( $child );
}
return $innerHTML;
}
chdir('asterisk-buch/2.1');
$dir = opendir('.');
while (false !== ($file = readdir($dir)))
{
if ($file{0} == '.') continue;
$page = new DOMDocument();
$olderr = error_reporting(0);
$page->loadHTMLFile($file);
error_reporting($olderr);
$xpath = new DOMXPath($page);
$html_new = "";
$class_names = array('section','chapter','appendix', 'glossary', 'index', 'preface');
foreach ($class_names as $cln)
{
$section = $xpath->query('//*[contains(concat( " ", @class, " " ), concat( " ", "' . $cln . '", " " ))]')->item(0);
$html_new = get_inner_html($section);
if (strlen($html_new) > 5)
break;
}
if (strlen($html_new) > 5)
{
file_put_contents($file, '' . $html_new);
echo "Writing $file\n";
}
else
{
echo "Error $file\n";
}
}
?>