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


PHP DOMDocument::createDocumentFragment方法代码示例

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


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

示例1: handleError

 public function handleError(\Dwoo\Exception $e)
 {
     $html = new \DOMDocument();
     $html->loadHTMLFile('lib/resources/exception.html');
     $message = $html->getElementById('message');
     $template = $html->createDocumentFragment();
     $template->appendXML($e->getMessage());
     $message->appendChild($template);
     unset($template);
     $php_version = $html->getElementById('php-version');
     $template = $html->createDocumentFragment();
     $template->appendXML(phpversion());
     $php_version->appendChild($template);
     unset($template);
     $dwoo_version = $html->getElementById('dwoo-version');
     $template = $html->createDocumentFragment();
     $template->appendXML(Core::VERSION);
     $dwoo_version->appendChild($template);
     unset($template);
     $exectime = $html->getElementById('exectime');
     $template = $html->createDocumentFragment();
     $template->appendXML(round(microtime(true) - $_SERVER['REQUEST_TIME'], 3));
     $exectime->appendChild($template);
     unset($template);
     echo $html->saveHTML();
 }
开发者ID:Keegomyneego,项目名称:cockamamei,代码行数:26,代码来源:Exception.php

示例2: boldCapitals

 function boldCapitals()
 {
     // gets an instance of the object to display
     $CI =& get_instance();
     // gets output of objects
     $page = $CI->output->get_output();
     // this page's HTML DOM object
     $dom = new DOMDocument();
     $dom->loadHTML($page);
     // gets element with 'p' tags
     $pList = $dom->getElementsByTagName('p');
     // search for the following characters
     $search = array('/([A-Z]+[A-Za-z]*)/');
     // repleaces characters we want to replace
     $replace = array('<strong>$1</strong>');
     // loops through each 'p' tag on the page
     foreach ($pList as $p) {
         if ($p->getAttribute('class' == 'lead')) {
             $string = $p->nodeValue;
             // replace characters with a bold and capitalized characters
             $p->nodeValue = preg_replace($search, $replace, $string);
             // create a new tag object
             $frag = $dom->createDocumentFragment();
             $frag->appendXML($string);
             // append new object to the element
             $p->nodeValue = '';
             $p->appendChild($frag);
         }
     }
     //output the changes back to the screen
     echo $dom->saveHTML();
 }
开发者ID:beckyzhou,项目名称:starter-lab03,代码行数:32,代码来源:Massage.php

示例3: iqWrapper

 static function iqWrapper($xml = false, $to = false, $type = false, $id = false)
 {
     $session = \Sessionx::start();
     $dom = new \DOMDocument('1.0', 'UTF-8');
     $iq = $dom->createElementNS('jabber:client', 'iq');
     $dom->appendChild($iq);
     if ($to != false) {
         $iq->setAttribute('to', $to);
     }
     if ($type != false) {
         $iq->setAttribute('type', $type);
     }
     global $language;
     if ($id == false) {
         $id = $session->id;
     }
     $iq->setAttribute('id', $id);
     if (isset($language)) {
         $iq->setAttribute('xml:lang', $language);
     }
     if (isset($session->user)) {
         $iq->setAttribute('from', $session->user . '@' . $session->host . '/' . $session->resource);
     }
     if ($xml != false) {
         if (is_string($xml)) {
             $f = $dom->createDocumentFragment();
             $f->appendXML($xml);
             $iq->appendChild($f);
         } else {
             $xml = $dom->importNode($xml, true);
             $iq->appendChild($xml);
         }
     }
     return $dom->saveXML($dom->documentElement);
 }
开发者ID:Hywan,项目名称:moxl,代码行数:35,代码来源:API.php

示例4: appendXml

 /**
  * Append an XML snippet.
  *
  * @param DOMNode $parent_node Attach the XML below this parent.
  * @param string  $xml         The XML to append.
  *
  * @return DOMNode The new child node.
  */
 public function appendXml($parent_node, $xml)
 {
     $node = $this->_xmldoc->createDocumentFragment();
     $node->appendXML($xml);
     $parent_node->appendChild($node);
     return $node;
 }
开发者ID:horde,项目名称:horde,代码行数:15,代码来源:Helper.php

示例5: getChildElements

 /**
  * Get the child objects
  * and render them as document fragment
  *
  * @param \DOMDocument $dom DOMDocument
  * @return \DOMDocumentFragment
  */
 public function getChildElements(\DOMDocument $dom)
 {
     $modelChildren = $this->model->getElements();
     $documentFragment = NULL;
     foreach ($modelChildren as $key => $modelChild) {
         $child = $this->createChildElementFromModel($modelChild);
         if ($child) {
             if ($child->noWrap() === TRUE) {
                 $childNode = $child->render();
             } else {
                 $childNode = $child->render('elementWrap');
                 if ($childNode) {
                     $childNode->setAttribute('class', $child->getElementWraps());
                 }
             }
             if ($childNode) {
                 $importedNode = $dom->importNode($childNode, TRUE);
                 if (!$documentFragment) {
                     $documentFragment = $dom->createDocumentFragment();
                 }
                 $documentFragment->appendChild($importedNode);
             }
         }
     }
     return $documentFragment;
 }
开发者ID:adrolli,项目名称:TYPO3.CMS,代码行数:33,代码来源:ContainerElementView.php

示例6: lettering

 /**
  * Our function called via Twig; it can do anything you want
  *
  * @return string
  */
 public function lettering($text = null, $class = 'chars')
 {
     if (!$text || strlen($text) === 0 || !method_exists(craft()->lettering, $class)) {
         return $text;
     }
     $dom = new LetteringDom();
     $dom->loadHTML(mb_convert_encoding('<div id="workingNode">' . $text . '</div>', 'HTML-ENTITIES', $this->encoding));
     $workingNode = $dom->getElementById('workingNode');
     $fragment = $dom->createDocumentFragment();
     foreach ($workingNode->childNodes as $node) {
         if ($node->nodeType !== 1) {
             continue;
         }
         $value = $node->nodeValue;
         $result = craft()->lettering->{$class}($value, $class);
         $node->nodeValue = '';
         $tempFragment = new LetteringDom();
         $tempFragment->loadHTML(mb_convert_encoding($result[$class], 'HTML-ENTITIES', $this->encoding));
         foreach ($tempFragment->getElementsByTagName('body')->item(0)->childNodes as $tempNode) {
             $tempNode = $node->ownerDocument->importNode($tempNode, true);
             $node->appendChild($tempNode);
         }
         $node->setAttribute('aria-label', trim(strip_tags($value)));
         $fragment->appendChild($node->cloneNode(true));
     }
     $workingNode->parentNode->replaceChild($fragment, $workingNode);
     $result = TemplateHelper::getRaw(preg_replace('~<(?:!DOCTYPE|/?(?:html|head|body))[^>]*>\\s*~i', '', $dom->saveHTML()));
     if (strlen(trim($result)) === 0) {
         $result = craft()->lettering->{$class}($text);
         return $result ? $result[$class] : $text;
     }
     return $result;
 }
开发者ID:sjelfull,项目名称:Craft-Lettering,代码行数:38,代码来源:LetteringTwigExtension.php

示例7: onRenderProductListBefore

 public function onRenderProductListBefore(FilterResponseEvent $event)
 {
     $app = $this->app;
     $request = $event->getRequest();
     $response = $event->getResponse();
     $id = $request->query->get('category_id');
     // category_idがない場合、レンダリングを変更しない
     if (is_null($id)) {
         return;
     }
     $CategoryContent = $app['category_content.repository.category_content']->find($id);
     // 登録がない、もしくは空で登録されている場合、レンダリングを変更しない
     if (is_null($CategoryContent) || $CategoryContent->getContent() == '') {
         return;
     }
     // 書き換えhtmlの初期化
     $html = $response->getContent();
     libxml_use_internal_errors(true);
     $dom = new \DOMDocument();
     $dom->loadHTML('<?xml encoding="UTF-8">' . $html);
     $dom->encoding = "UTF-8";
     $dom->formatOutput = true;
     // 挿入対象を取得
     $navElement = $dom->getElementById('page_navi_top');
     if (!$navElement instanceof \DOMElement) {
         return;
     }
     $template = $dom->createDocumentFragment();
     $template->appendXML(htmlspecialchars($CategoryContent->getContent()));
     $node = $dom->importNode($template, true);
     $navElement->insertBefore($node);
     $newHtml = html_entity_decode($dom->saveHTML(), ENT_NOQUOTES, 'UTF-8');
     $response->setContent($newHtml);
     $event->setResponse($response);
 }
开发者ID:ryo-endo,项目名称:category-content-plugin,代码行数:35,代码来源:CategoryContentLegacyEvent.php

示例8: foo

function foo()
{
    $d = new DOMDocument();
    $c = $d->createDocumentFragment();
    $g = $d->createElement('fiz', 'buz');
    $h = $d->createElement('red', 'xen');
    $c->appendChild($g);
    $c->appendChild($h);
    return $c->childNodes;
}
开发者ID:badlamer,项目名称:hhvm,代码行数:10,代码来源:dom-iter-lifetime-v2.php

示例9: appendXMLString

 /**
  * @param \DOMNode $node
  * @param string   $val
  *
  * @return bool
  */
 protected final function appendXMLString(\DOMNode $node, $val)
 {
     if (strlen($val) > 0) {
         $frag = $this->dom->createDocumentFragment();
         $frag->appendXML($val);
         $node->appendChild($frag);
         return true;
     }
     return false;
 }
开发者ID:ccq18,项目名称:EduSoho,代码行数:16,代码来源:XmlEncoder.php

示例10: load

 /**
  * Loads a partial into the template
  *
  * @param string $source The path and file name to the partial
  * @param string $target The target XPath to place the partial in
  */
 protected function load($source, $target)
 {
     $xpath = new DOMXPath($this->document);
     $items = $xpath->query($target);
     if ($items->length > 0) {
         $source = $this->parse($source);
         $fragment = $this->document->createDocumentFragment();
         $fragment->appendXML($source);
         $items->item(0)->appendChild($fragment);
     }
 }
开发者ID:TheProjecter,项目名称:panda-php,代码行数:17,代码来源:HTML.php

示例11: __toString

 public function __toString()
 {
     $doc = new DOMDocument();
     $doc->loadXML('<add/>');
     foreach ($this->documents as $document) {
         $frag = $doc->createDocumentFragment();
         $frag->appendXml((string) $document);
         $doc->documentElement->appendChild($frag);
     }
     return $doc->saveXml($doc->documentElement);
 }
开发者ID:olhsha,项目名称:OpenSKOS2tempMeertens,代码行数:11,代码来源:Documents.php

示例12: toXLIFF

 /**
  * Converts HTML to the corresponding XLIFF representation.
  *
  * @return string
  *   The source HTML converted to XLIFF.
  */
 public function toXLIFF($pretty_print = FALSE)
 {
     $this->doc->formatOutput = $pretty_print;
     // Do not use getElementById to comply with older versions of libxml.
     // getElementById doesn't work properly on libxml 2.7.6 (CentOS)
     $xpath = new \DOMXPath($this->doc);
     $wrapper_div = $xpath->query("//*[@id='eggs-n-cereal-dont-ever-use-this-id']")->item(0);
     $out = $this->doc->createDocumentFragment();
     $domNodeList = array();
     for ($i = 0; $i < $wrapper_div->childNodes->length; ++$i) {
         $domNodeList[] = $wrapper_div->childNodes->item($i);
     }
     $this->sanitizeMixedDomNodeList($this->doc, $domNodeList);
     foreach ($domNodeList as $domNode) {
         if ($output = $this->convert($domNode)) {
             $out->appendChild($output);
         }
     }
     return $this->doc->saveXML($out);
 }
开发者ID:ShinyAds,项目名称:eggs-n-cereal,代码行数:26,代码来源:Converter.php

示例13: getRecommendationsDom

 public function getRecommendationsDom($html = null)
 {
     if (!$html) {
         $html = $this->toHtml();
     }
     $dom = new DOMDocument('1.0', 'utf8');
     $dom->loadXml('<root/>');
     $fragment = $dom->createDocumentFragment();
     $fragment->appendXML($html);
     return $fragment;
 }
开发者ID:ExtensionsStore,项目名称:AutoCompleteRecommendations,代码行数:11,代码来源:Recommendation.php

示例14: onRenderProductListBefore

 /**
  * onRenderProductListBefore.
  *
  * @param FilterResponseEvent $event
  */
 public function onRenderProductListBefore(FilterResponseEvent $event)
 {
     log_info('CategoryContent eccube.event.render.product_list.before start');
     $app = $this->app;
     $request = $event->getRequest();
     $response = $event->getResponse();
     $id = $request->query->get('category_id');
     // category_idがない場合、レンダリングを変更しない
     if (!$id) {
         return;
     }
     $CategoryContent = $app['eccube.plugin.category_content.repository.category_content']->find($id);
     // 登録がない、もしくは空で登録されている場合、レンダリングを変更しない
     if (!$CategoryContent || !$CategoryContent->getContent()) {
         log_info('CategoryContent eccube.event.render.product_list.before  not content end');
         return;
     }
     // twigから挿入するhtmlを生成する
     $snipet = $this->app->renderView('CategoryContent/Resource/template/default/category_content.twig', array('PluginCategoryContent' => $CategoryContent));
     // htmlの挿入処理
     $html = $response->getContent();
     $search = self::CATEGORY_CONTENT_TAG;
     if (strpos($html, $search)) {
         // タグの位置に挿入する場合
         log_info('Render category content with ', array('CATEGORY_CONTENT_TAG' => $search));
         $replace = $search . $snipet;
         $newHtml = str_replace($search, $replace, $html);
         $response->setContent($newHtml);
     } else {
         // Elementを探して挿入する場合
         libxml_use_internal_errors(true);
         $dom = new \DOMDocument();
         $dom->loadHTML('<?xml encoding="UTF-8">' . $html);
         $dom->encoding = 'UTF-8';
         $dom->formatOutput = true;
         // 基準となるElementを取得
         $navElement = $dom->getElementById('topicpath');
         if (!$navElement instanceof \DOMElement) {
             log_info('CategoryContent eccube.event.render.product_list.before  not have dom end');
             return;
         }
         // 挿入するNodeを生成
         $template = $dom->createDocumentFragment();
         $template->appendXML(htmlspecialchars($snipet));
         $node = $dom->importNode($template, true);
         // 基準となるElementの直後にNodeを挿入し、Responsを書き換え
         $navElement->parentNode->insertBefore($node, $navElement->nextSibling);
         $newHtml = html_entity_decode($dom->saveHTML(), ENT_NOQUOTES, 'UTF-8');
         $response->setContent($newHtml);
     }
     $event->setResponse($response);
     log_info('CategoryContent eccube.event.render.product_list.before end');
 }
开发者ID:EC-CUBE,项目名称:category-content-plugin,代码行数:58,代码来源:EventLegacy.php

示例15: foo

function foo()
{
    $html = '<b>Hello</b><i>World</i>';
    $doc = new DOMDocument();
    $element = $doc->createDocumentFragment();
    $element->appendXML($html);
    foreach ($element->childNodes->getIterator() as $child) {
        $element = null;
        $doc = null;
        var_dump($child->nodeValue);
    }
}
开发者ID:badlamer,项目名称:hhvm,代码行数:12,代码来源:1680.php


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