Example #1
0
function xhtml_diff_highlight($a, $b, $bail = 0)
{
    $parser = new XMLObjectParser();
    $parser->parse("<difference set='a'>{$a}</difference>");
    $atree = $parser->tree;
    while (is_array($atree[0]) and count($atree[0]) == 0) {
        array_shift($atree);
    }
    //$atree = $atree[0][0]->children;
    //print("Tree A: "); var_dump($atree);
    $parser = new XMLObjectParser();
    $parser->parse("<difference set='b'>{$b}</difference>");
    $btree = $parser->tree;
    while (is_array($btree[0]) and count($btree[0]) == 0) {
        array_shift($btree);
    }
    //$btree = $btree[0][0]->children;
    //print("Tree B: "); var_dump($btree);
    while ($b = array_shift($btree)) {
        $a = array_shift($atree);
        print_r($a);
        print_r($b);
        //	if(!$a) $a = array();
        //	if(!$b) $b = array();
        $a = xhtml_child_split($a);
        while (!$a[0]) {
            array_shift($a);
        }
        $b = xhtml_child_split($b);
        while (!$b[0]) {
            array_shift($b);
        }
        $o .= xml_diff_tree($a, $b, $bail);
    }
    return $o;
}
<?php

require "xml.php";
$data = "<html><head><title>Hello!</title></head><body bgcolor='foo'><p> This is a paragraph </p><p> this is another</p><ul><li>Test!</li></ul></body></html>";
//	$data = "<html><head><title>Hello!</title></head></html>";
$parser = new XMLObjectParser();
$parser->parse($data);
print_r($parser->tree);