本文整理汇总了PHP中domDocument::removeChild方法的典型用法代码示例。如果您正苦于以下问题:PHP domDocument::removeChild方法的具体用法?PHP domDocument::removeChild怎么用?PHP domDocument::removeChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类domDocument
的用法示例。
在下文中一共展示了domDocument::removeChild方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: saveHtml
public function saveHtml($refresh = true)
{
if (extension_loaded('xml') and class_exists('DomXpath')) {
if (get_parent_class($this) === __CLASS__) {
$node = $this->node;
} elseif (get_parent_class($this) === false) {
$node = $this;
} else {
return false;
}
if (!is_a($node, jqmel)) {
return false;
}
if ($node->_length === false) {
return false;
}
$docm = jqm_use($node->_parentElement);
//$docm->__documentRaw = preg_replace('/\s+/',' ',$docm->__documentRaw);
$doc = $docm->_DOM;
if ($doc->doctype) {
$doc->removeChild($doc->doctype);
}
$k = key($this->_domId);
if ($refresh == true) {
$this->refresh();
$node->_attributes['data-dom-id'] = $k;
} else {
if ($this->_domId[$k] === NULL) {
$attr = $node->_attributes;
unset($attr['data-dom-id']);
$node->_attributes = $attr;
} else {
$node->_attributes['data-dom-id'] = $this->_domId[$k];
}
}
$newdoc = new domDocument();
$dom = $node->dom()->get();
$newdoc->loadhtml(mb_convert_encoding($dom->lastdom, 'HTML-ENTITIES', 'UTF-8'));
$newdoc->removeChild($newdoc->doctype);
$newdoc_get = $newdoc->getElementsByTagName($node->_name);
//Finder
$xpath = new DomXpath($doc);
$find = $xpath->query($node->_path);
if ($find->length > 0) {
$frag = $doc->importNode($newdoc_get->item(0), true);
if ($find->item(0)->parentNode) {
$find->item(0)->parentNode->replaceChild($frag, $find->item(0));
}
/* $output = $doc->saveHTML();
$hasHTML = (strip_tags($docm->__documentRaw,'<html>') !==$docm->__documentRaw);
if($hasHTML===false){
//Return just a partial html
$docm->__documentRaw = str_ireplace(array('<html>','<body>','</html>','</body>','<head>','</head>'),'',$output);
}else{
$docm->__documentRaw = $output;
} */
$node->_attributes['data-dom-id'] = $this->_domId[$k];
return $frag->getNodepath();
}
}
}
示例2: getTextBetweenTags
//.........这里部分代码省略.........
}
if (!isset($CFG->filter_jsxgraph_width)) {
set_config('filter_jsxgraph_width', '500');
}
if (!isset($CFG->filter_jsxgraph_height)) {
set_config('filter_jsxgraph_height', '400');
}
// a new dom object
$dom = new domDocument();
$dom->formatOutput = true;
// load the html into the object
if ($strict == 1) {
$dom->loadXML($html);
} else {
libxml_use_internal_errors(true);
$htmlutf8 = mb_convert_encoding($html, 'HTML-ENTITIES', $encoding);
$dom->loadHTML($htmlutf8);
libxml_use_internal_errors(false);
}
// discard white space
$dom->preserveWhiteSpace = false;
$dom->strictErrorChecking = false;
$dom->recover = true;
// the tag by its tag name
$content = $dom->getElementsByTagname($tag);
if (count($content) > 0) {
$PAGE->requires->js(new moodle_url($CFG->wwwroot . '/filter/jsxgraph/jsxgraphcore.js'));
}
// Iterate backwards through the jsxgraph tags
$i = $content->length - 1;
while ($i > -1) {
$item = $content->item($i);
// Read attributes
$w = $item->getAttribute('width');
if ($w == "") {
$w = $CFG->filter_jsxgraph_width;
}
$h = $item->getAttribute('height');
if ($h == "") {
$h = $CFG->filter_jsxgraph_height;
}
$b = $item->getAttribute('box');
if ($b == "") {
$b = $CFG->filter_jsxgraph_divid . $i;
}
$brd = $item->getAttribute('board');
if ($brd == "") {
$brd = $CFG->filter_jsxgraph_boardvar . $i;
}
/* Create new div element containing JSXGraph */
$out = $dom->createElement('div');
$a = $dom->createAttribute('id');
$a->value = $b;
$out->appendChild($a);
$a = $dom->createAttribute('class');
$a->value = "jxgbox";
$out->appendChild($a);
$a = $dom->createAttribute('style');
$a->value = "width:" . $w . "px; height:" . $h . "px; ";
$out->appendChild($a);
$t = $dom->createTextNode("");
$out->appendChild($t);
$out = $dom->appendChild($out);
// Replace <jsxgraph> by <div>
$item->parentNode->replaceChild($out, $item);
$code = "";
$needGXT = false;
$url = $item->getAttribute('file');
if ($url != "") {
$code = "var " . $brd . " = JXG.JSXGraph.loadBoardFromFile('" . $b . "', '" . $url . "', 'Geonext');";
$needGXT = true;
} else {
$url = $item->getAttribute('filestring');
if ($url != "") {
$code = "var " . $brd . " = JXG.JSXGraph.loadBoardFromString('" . $b . "', '" . $url . "', 'Geonext');";
$needGXT = true;
} else {
// Plain JavaScript code
$code = $item->nodeValue;
}
}
// Place JavaScript code at the end of the page.
$PAGE->requires->js_init_call($code);
if ($needGXT) {
$PAGE->requires->js(new moodle_url($CFG->wwwroot . '/filter/jsxgraph/GeonextReader.js'));
}
--$i;
}
// remove DOCTYPE
$dom->removeChild($dom->firstChild);
// remove <html><body></body></html>
//$dom->replaceChild($dom->firstChild->firstChild->firstChild, $dom->firstChild);
//return $dom->saveXML();
$str = $dom->saveHTML();
$str = str_replace("<body>", "", $str);
$str = str_replace("</body>", "", $str);
$str = str_replace("<html>", "", $str);
$str = str_replace("</html>", "", $str);
return $str;
}
示例3: run
public function run($str = nULL)
{
if (!is_null($str)) {
$regex = '/<([a-z0-9\\-]+)(.*?)>(?:(.*?)(<\\/\\1>))?/ix';
if (is_a($str, jqmel)) {
$str = $str->dom()->get()->lastdom;
} elseif (is_callable($str)) {
$str = call_user_func($str, array());
}
$str = preg_replace('/\\s+/', ' ', $str);
if (preg_match($regex, $str, $match)) {
$match[2] = rtrim($match[2], '/');
}
$document = jqm_use($this->node->_parentElement);
$np = $this->node->next()->get();
$npp = $this->node->prev()->get();
$par = $this->node->parent();
$wrap = $str;
if (!is_a($par->get(), jqmel)) {
return;
}
$rec = $document->_DOM;
if ($rec->doctype) {
$rec->removeChild($rec->doctype);
}
$xpath = new domxpath($rec);
$find = $xpath->query($this->node->_path);
if ($find->length > 0) {
$child = new domDocument();
$child->loadHtml($wrap);
if ($child->doctype) {
$child->removeChild($child->doctype);
}
$chf = $child->getElementsByTagName($match[1]);
$node = $this->node->__toDomElement();
$frag = $child->importNode($node, true);
$depth = $this->getDeepest($chf->item(0));
$save = $depth->appendChild($frag);
//Import to document
$frag = $rec->importNode($chf->item(0), true);
$newsave = $find->item(0)->parentNode->replaceChild($frag, $find->item(0));
$new_path = explode('/', $frag->getNodePath());
$p_path = array_filter(explode('/', $save->getNodePath()));
//$p_path = array_pop($p_path);
$htm = array_search('html', $p_path);
if ($htm) {
unset($p_path[$htm]);
unset($p_path[$htm + 1]);
}
$new_path = array_merge($new_path, $p_path);
$sh = array_pop($new_path);
array_pop($new_path);
$ele_path = ltrim($newsave->getNodePath(), '/');
$this->node->_parent_path = implode('/', $new_path);
$this->node->_path = $this->node->_parent_path . '/' . $sh;
$wrap = $rec->saveHtml($frag->parentNode);
$wrap = substr($wrap, strpos($wrap, '>') + 1);
if (!empty($par->get()->_localName)) {
$wrap = substr($wrap, 0, strripos($wrap, $par->get()->_localName));
$par->get()->html($wrap);
}
$find = $this->node->getPathById();
if ($find) {
$this->node->_path = $find;
}
if ($this->node->trace) {
$key = $this->node->trace->key();
$this->node->trace->next();
$n = $this->node->trace->current();
if ($key > 0) {
$this->node->trace->seek($key - 1);
$p = $this->node->trace->current();
}
if ($p and is_a($p, jqmel)) {
$find = $p->getPathById();
if ($find) {
$p->_path = $find;
//var_dump($key,$p);
}
}
if ($n and is_a($n, jqmel)) {
$find = $n->getPathById();
if ($find) {
$n->_path = $find;
}
}
unset($p);
unset($n);
}
}
}
}