现在需要得到所有<a>标签的中文内容,php代码如下: 复制代码 代码如下: <?php //将html/xml文件转换成DOM树 $dom = new DOMDocument(); $dom->loadHTMLFile("hao.html");
//得到所有class为fix的dl标签
// example 1: for everything with an id //$elements = $xpath->query("//*[@id]");
// example 2: for node data in a selected id //$elements = $xpath->query("/html/body/div[@id='yourTagIdHere']");
// example 3: same as above with wildcard //$elements = $xpath->query("*/div[@id='yourTagIdHere']"); $xpath = new DOMXPath($dom); $dls = $xpath->query('//dl[@class="fix"]');
foreach ($dls as $dl) { $spans = $dl->childNodes; foreach ($spans as $span) { echo trim($span->textContent)."\t"; } echo "\n"; } ?>