現在需要得到所有<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"; } ?>