当前位置: 首页>>代码示例>>PHP>>正文


PHP DomDocument::removeChild方法代码示例

本文整理汇总了PHP中DomDocument::removeChild方法的典型用法代码示例。如果您正苦于以下问题:PHP DomDocument::removeChild方法的具体用法?PHP DomDocument::removeChild怎么用?PHP DomDocument::removeChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DomDocument的用法示例。


在下文中一共展示了DomDocument::removeChild方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: run

 public function run($str = NULL)
 {
     if ($str == NULL) {
         return $this;
     }
     $document = jqm_use($this->node->_parentElement);
     $dom = $document->_DOM;
     if ($dom->doctype) {
         $dom->removeChild($dom->doctype);
     }
     $find = $this->node->getPathById($dom);
     if (!$find) {
         $find = $this->node->_path;
     }
     $xpath = new DomXpath($dom);
     $find = $xpath->query($find);
     if ($find->length > 0) {
         $child = new DomDocument();
         $child->loadHtml($str);
         if ($child->doctype) {
             $child->removeChild($child->doctype);
         }
         $child->normalize();
         $frag = $dom->importNode($child->firstChild->firstChild->firstChild, true);
         $save = $find->item(0)->parentNode->insertBefore($frag, $find->item(0));
         $this->node->_path = $save->nextSibling->getNodePath();
         $document->_DOM = $dom;
     }
     return $this;
 }
开发者ID:Webictbyleo,项目名称:JqueryPhp,代码行数:30,代码来源:before.php

示例2: run

 public function run($str = NULL)
 {
     if ($str == NULL) {
         return $this;
     }
     $dom = $this->node->dom()->get();
     $this->node->_lastDom = $dom->lastdom . $str;
     $rec = new DomDocument();
     $rec->loadHtml($str);
     if ($rec->doctype) {
         $rec->removeChild($rec->doctype);
     }
     $document = jqm_use($this->node->_parentElement);
     $dom = $document->_DOM;
     if ($dom->doctype) {
         $dom->removeChild($dom->doctype);
     }
     $body = $rec->childNodes->item(0)->firstChild;
     $frag = $dom->importNode($body, true);
     $xpath = new DomXpath($dom);
     $find = $this->node->getPathByID($dom);
     $find = $xpath->query($find);
     if ($find->length > 0) {
         $save = $find->item(0)->parentNode->insertBefore($frag->firstChild, $find->item(0)->nextSibling);
         $this->node->_path = $save->previousSibling->getNodePath();
         $document->_DOM = $dom;
     }
     return $this;
 }
开发者ID:Webictbyleo,项目名称:JqueryPhp,代码行数:29,代码来源:after.php

示例3: truncatehtml

 public function truncatehtml($html, $minimum)
 {
     $oldDocument = new \DomDocument();
     $html = mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8');
     $oldDocument->loadHTML('<div>' . $html . '</div>');
     // remove DOCTYPE, HTML and BODY tags
     $oldDocument->removeChild($oldDocument->firstChild);
     $oldDocument->replaceChild($oldDocument->firstChild->firstChild->firstChild, $oldDocument->firstChild);
     $currentLength = 0;
     // displayed text length (without markup)
     $newDocument = new \DomDocument();
     foreach ($oldDocument->documentElement->childNodes as $node) {
         if ($node->nodeType != 3) {
             // not text node
             $imported = $newDocument->importNode($node, true);
             $newDocument->appendChild($imported);
             // copy original node to output document
             $currentLength += strlen(html_entity_decode($imported->nodeValue));
             if ($currentLength >= $minimum) {
                 // check if the minimum is reached
                 break;
             }
         }
     }
     $output = $newDocument->saveHTML();
     return html_entity_decode($output);
 }
开发者ID:sitobcn82,项目名称:blog,代码行数:27,代码来源:TruncateHtmlExtension.php

示例4: die

if (!$buf) {
    die($xml);
}
$mime_type = NULL;
if (isset($_REQUEST['filter_extension'])) {
    require_once dirname(__FILE__) . '/includes/mime.inc.php';
    $mime_type = getMimeTypefromExtension($_REQUEST['filter_extension']);
} else {
    if (isset($_REQUEST['filter_mime'])) {
        $mime_type = $_REQUEST['filter_mime'];
    }
}
if (!is_null($mime_type)) {
    $user_node = $dom->documentElement;
    $user_node_new = $user_node->cloneNode(false);
    $applications_nodes = $user_node->getElementsByTagName('application');
    foreach ($applications_nodes as $application_node) {
        $found_mime = false;
        $mime_nodes = $application_node->getElementsByTagName('mime');
        foreach ($mime_nodes as $mime_node) {
            if ($mime_node->getAttribute('type') == $mime_type) {
                $user_node_new->appendChild($application_node->cloneNode(true));
                break;
            }
        }
    }
    $dom->removeChild($user_node);
    $dom->appendChild($user_node_new);
}
header('Content-Type: text/xml');
echo $dom->saveXML();
开发者ID:skdong,项目名称:nfs-ovd,代码行数:31,代码来源:applications.php

示例5: html

 public static function html($var, $array = null, $default = '')
 {
     $var = (string) self::getVal($var, $array, $default);
     //$var = Filter::utf8($var);
     if (!preg_match('/\\S/', $var)) {
         return $default;
     }
     // corrige les </li>&#13;
     $var = preg_replace('#>[\\r\\n]+#m', '>', $var);
     //ignore error
     libxml_use_internal_errors(true);
     $dom = new \DomDocument('1.0', 'UTF-8');
     $dom->recover = true;
     // this is the trick
     $var = '<div>' . $var . '</div>';
     try {
         // hack to preserve UTF-8 characters
         //http://stackoverflow.com/questions/3548880/php-dom-utf-8-problem
         $dom->loadHTML('<?xml encoding="UTF-8">' . $var);
         // hack fix utf-8
         $dom->encoding = 'UTF-8';
     } catch (\Exception $e) {
     }
     if (!function_exists('filterHtmlCleanChild')) {
         function filterHtmlCleanChild(DOMElement $p, $removeTag, $removeAttr)
         {
             if ($p->hasChildNodes()) {
                 foreach ($p->childNodes as $c) {
                     // on delete ce fils
                     if (in_array($c->nodeName, $removeTag)) {
                         $p->removeChild($c);
                     } elseif ($c->nodeType == XML_ELEMENT_NODE) {
                         filterHtmlCleanChild($c, $removeTag, $removeAttr);
                     }
                 }
             }
             foreach ($removeAttr as $ra) {
                 $p->removeAttribute($ra);
                 /** 		 	test
                          if ( $ra == 'onkeydown' ) {
                          if ( $va = $p->getAttribute('onkeydown') ) {
                          $p->removeAttribute($ra);
                          $rgx = '#*media\{id:([0-9]*)\}*#';
                          preg_match($rgx, $va, $m);
                          $r = array();
                          if ( isset($m[1]) ) { $p->setAttribute($ra,"media{id:".$m[1]."}"); }
                          }
                         */
             }
             return $p;
         }
     }
     $removeAttr = array('onclick', 'ondblclick', 'onkeydown', 'onkeypress', 'onkeyup', 'onload', 'onmousedown', 'onmousemove', 'onmouseout', 'onmouseover', 'onmouseup', 'onunload');
     $removeTag = array('script');
     foreach ($dom->childNodes as $p) {
         if ($p->nodeType == XML_PI_NODE) {
             $dom->removeChild($p);
         } elseif ($p->hasChildNodes()) {
             filterHtmlCleanChild($p, $removeTag, $removeAttr);
         }
     }
     $dom->normalizeDocument();
     $r = $dom->saveXML($dom->childNodes->item(1)->childNodes->item(0)->childNodes->item(0), LIBXML_NOEMPTYTAG);
     $r = preg_replace('#^<div>#', '', $r);
     $var = preg_replace('#</div>$#', '', $r);
     // fix certain navigateur compte 2 <br> pour <br></br>, et n'accepte pas les <iframe />
     $var = preg_replace('#<br></br>#', '<br />', $var);
     return self::setVal($var, $default);
 }
开发者ID:4Publish,项目名称:4p_core,代码行数:69,代码来源:Filter.php

示例6: parseFull

 private function parseFull($xml, $encoding = null)
 {
     $dom = new \DomDocument();
     if ($encoding) {
         $xml = '<?xml encoding="' . $encoding . '">' . $xml;
     }
     libxml_disable_entity_loader();
     // prevents XXE attacks
     $prevErrorSetting = libxml_use_internal_errors(true);
     if ($dom->loadXML($xml)) {
         if ($encoding) {
             foreach ($dom->childNodes as $item) {
                 if ($item->nodeType == XML_PI_NODE) {
                     $dom->removeChild($item);
                     break;
                 }
             }
             $dom->encoding = $encoding;
         }
         libxml_use_internal_errors($prevErrorSetting);
         return new Proxy(simplexml_import_dom($dom), $this);
     }
     $errors = libxml_get_errors();
     libxml_clear_errors();
     libxml_use_internal_errors($prevErrorSetting);
     $message = 'Incorrect xml passed.';
     foreach ($errors as $error) {
         $message .= '\\nline: ' . $error->line . '; column: ' . $error->column . '; ' . $error->message;
     }
     throw new \arc\UnknownError($message, \arc\exceptions::ILLEGAL_ARGUMENT);
 }
开发者ID:poef,项目名称:ariadne,代码行数:31,代码来源:Parser.php


注:本文中的DomDocument::removeChild方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。