/** * $result = html\to_dom("<html><head><title>teste</title></head><body style='background:red;'>ola <span id='testando'>teste</span> do mundo</body></html>"); // gets a array with id of the first Child and the code of the rest.. * echo $result["code"]; // to show the code * echo "document.body.appendChild(".$result["id"].")"; // To show the result in document.body */ function to_dom($html) { if (is_string($html)) { $type = "string"; } else { $type = get_class($html); } switch ($type) { case "DOMDocument": case "DOMElement": $id = $html->nodeName . "_" . md5(uniqid()) . "_element"; if ($html->nodeName != "#document") { $code = "var " . $id . " = document.createElement('" . $html->nodeName . "');\n"; } else { $code = ""; } if (!!$html->attributes) { foreach ($html->attributes as $attr) { $code .= $id . ".setAttribute('" . $attr->name . "', '" . jse($attr->value) . "');\n"; } } if (!!$html->childNodes) { foreach ($html->childNodes as $child) { if ($child->nodeType == XML_TEXT_NODE) { $code .= $id . ".appendChild(document.createTextNode('" . htmlentities(strip_nl($child->nodeValue)) . "'));\n"; } else { $element = to_dom($child); $code .= $element["code"]; if ($html->nodeName != "#document") { $code .= $id . ".appendChild(" . $element["id"] . ");\n"; } else { $id = $element["id"]; } } } } return array("code" => $code, "id" => $id); break; case "DOMDocumentType": return array("code" => "", "id" => ""); break; default: case "string": $dom = new DOMDocument(); $dom->strictErrorChecking = false; $dom->loadHTML($html); $result = to_dom($dom); return $result; break; } return NULL; }
/** * Compare the two schemas and echo the results. * * @param string $schema1 The first schema (serialized). * @param string $schema2 The second schema (serialized). * @return void */ function do_compare($schema1, $schema2) { if (empty($schema1) || empty($schema2)) { echo_error('Both schemas must be given.'); return; } $unserialized_schema1 = unserialize(strip_nl($schema1)); $unserialized_schema2 = unserialize(strip_nl($schema2)); $results = DbDiff::compare($unserialized_schema1, $unserialized_schema2); if (count($results) > 0) { echo '<h3>Found differences in ' . count($results) . ' table' . s(count($results)) . ':</h3>'; echo '<ul id="differences">'; foreach ($results as $table_name => $differences) { echo '<li><strong>' . $table_name . '</strong><ul>'; foreach ($differences as $difference) { echo '<li>' . $difference . '</li>'; } echo '</ul></li>'; } echo '</ul>'; } else { echo '<p>No differences found.</p>'; } }