Example #1
1
if (empty($word)) {
    exit('你想查啥?');
}
//解析XML并查询
$xml = new DOMDocument('1.0', 'utf-8');
$xml->load('./039_dict.xml');
$xpath = new DOMXPATH($xml);
$sql = '/dict/word[mean="' . $word . '"]/mean';
$words = $xpath->query($sql);
if ($words->length == 0) {
    echo 'sorry';
    exit;
}
//查到了
$goods = $words->item(0);
echo '货号:' . $word . '<br />';
echo '名字:', $goods->nextSibling->nodeValue, '<br />';
echo '价钱:', $goods->nextSibling->nextSibling->nodeValue, '<br />';
//////////////////////////////////////////////////////
$xml->loadhtmlfile('./039.html');
$xpath = new DOMXPATH($xml);
$sql1 = '//h2';
echo $xpath->query($sql1)->item(0)->nodeValue;
echo '<hr>';
//查询id="abc"的div节点
$sql = '//div[@id="abc"]';
echo $xpath->query($sql)->item(0)->nodeValue;
echo '<br />';
//分析第2个div下的p下的相邻span的第2个span的内容
$sql = '//div/p/span[2]';
echo $xpath->query($sql)->item(0)->nodeValue;
Example #2
0
    $doc = new DOMDocument();
    $doc->appendChild($doc->importNode($el, TRUE));
    $html = trim($doc->saveHTML());
    $tag = $el->nodeName;
    $html = preg_replace('@^<' . $tag . '[^>]*>|</' . $tag . '>$@', '', $html);
    //update relative links
    // TODO: is is required?
    //return preg_replace('~href="(.*)_4.4/([^"]+).html"~', 'href="${1}4.4/${2}.php"', $html);
    return $html;
}
if (!isset($keyword) or $keyword == "") {
    $keyword = "eclipse 4.4, eclipse, new and noteworthy";
}
$file = basename($App->getScriptName(), ".php") . '.html';
$doc = new DOMDocument();
$doc->loadhtmlfile($file);
$body = $doc->getElementsByTagName('body')->item(0);
$body = innerHTML($body);
$title = $doc->getElementsByTagName('title')->item(0);
$title = innerHTML($title);
#
# Begin: page-specific settings.  Change these.
$pageTitle = $title;
$pageKeywords = $keyword;
$pageAuthor = "";
$html = $body;
//$html .='</div></div>';
$html = mb_convert_encoding($html, "HTML-ENTITIES", "auto");
$App->Promotion = FALSE;
// if theme is not provided by caller, we specify "current one", explicitly hard-coded
if (!isset($theme)) {