<?php $hhc = new hhc(); $t = getContentTree(); $hhc->setContentTree($t); $hhc->setOutFileName('test.hhc'); $hhc->output(); function getContentTree() { $doc = new DOMDocument("1.0", "UTF-8"); //$doc->loadHTMLFile('E:\\shopexts\\trunk\\docs\\t2t\\index.html'); $doc->loadHTMLFile('index.html'); $xp = new DOMXPath($doc); $xpathString = "//html/body/*[@class='toc']/ol/li/a"; $nodes = $xp->query($xpathString); $i = 0; #获取第一级 foreach ($nodes as $node) { $attri = $node->attributes->item(0)->nodeValue; $value = $node->nodeValue; $topics[$i]['attri'] = $attri; $topics[$i]['value'] = $value; $i++; } #获取第二级 foreach ($topics as $t_key => $topic) { $xpathString = "//html/body/*[@class='toc']/ol/li/a[@href='" . $topic['attri'] . "']/parent::*/ul/li/a"; $nodes = $xp->query($xpathString); $i = 0; foreach ($nodes as $node) { $attri = $node->attributes->item(0)->nodeValue;
<?php define('T2TFILE', 'index.html'); define('PRJNAME', 'ststm'); # $hhc = new hhc(); $hhc->setT2tFile(T2TFILE); $hhc->setProjectName(PRJNAME); $hhc->setHhcFile(); $hhc->output(); # $hhp = new hhp(); $hhp->setT2tFile(T2TFILE); $hhp->setProjectName(PRJNAME); $hhp->setChmFile(); $hhp->setHhpFile(); $hhp->setHhcFile(); $hhp->output(); class hhp { var $_filelist; var $_conf; function setT2tFile($name) { $this->_t2tfile = $name; } function setProjectName($name) { $this->_projectname = $name; } function setChmFile()