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


PHP DomDocument::saveHTML方法代码示例

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


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

示例1: render

 public function render($internal = false)
 {
     if (empty($this->templateDocument)) {
         $this->compile();
     }
     return $this->templateDocument->saveHTML();
 }
开发者ID:dw250100785,项目名称:b8framework,代码行数:7,代码来源:Template.php

示例2: loadRfc

 /**
  * @param string $rfcLocation
  */
 private function loadRfc($rfcLocation, $rfcCode)
 {
     // Suppress HTML5 errors
     libxml_use_internal_errors(true);
     $this->document = new \DOMDocument();
     $this->document->loadHTMLFile($rfcLocation);
     // Turn errors back on
     libxml_use_internal_errors(false);
     $this->rfc = new Rfc();
     $this->rfc->setCode($rfcCode);
     $this->rfc->setRawContent($this->document->saveHTML());
 }
开发者ID:shakyShane,项目名称:php-rfc-digestor,代码行数:15,代码来源:RfcBuilder.php

示例3: setUp

 protected function setUp()
 {
     // Setup DOM
     $this->domDocument = new \DOMDocument('1', 'UTF-8');
     $html = $this->domDocument->createElement('html');
     $this->domAnchor = $this->domDocument->createElement('a', 'fake');
     $this->domAnchor->setAttribute('href', 'http://php-spider.org/contact/');
     $this->domDocument->appendChild($html);
     $html->appendChild($this->domAnchor);
     $this->uri = new DiscoveredUri(new Uri($this->domAnchor->getAttribute('href')));
     // Setup Spider\Resource
     $content = $this->domDocument->saveHTML();
     $this->spiderResource = new Resource($this->uri, new Response(200, [], $content));
 }
开发者ID:ggnet,项目名称:php-spider,代码行数:14,代码来源:DiscovererTestCase.php

示例4: 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

示例5: assertMatchesXpath

    protected function assertMatchesXpath($html, $expression, $count = 1)
    {
        $dom = new \DomDocument('UTF-8');
        try {
            // Wrap in <root> node so we can load HTML with multiple tags at
            // the top level
            $dom->loadXml('<root>'.$html.'</root>');
        } catch (\Exception $e) {
            return $this->fail(sprintf(
                "Failed loading HTML:\n\n%s\n\nError: %s",
                $html,
                $e->getMessage()
            ));
        }
        $xpath = new \DOMXPath($dom);
        $nodeList = $xpath->evaluate('/root'.$expression);

        if ($nodeList->length != $count) {
            $dom->formatOutput = true;
            $this->fail(sprintf(
                "Failed asserting that \n\n%s\n\nmatches exactly %s. Matches %s in \n\n%s",
                $expression,
                $count == 1 ? 'once' : $count . ' times',
                $nodeList->length == 1 ? 'once' : $nodeList->length . ' times',
                // strip away <root> and </root>
                substr($dom->saveHTML(), 6, -8)
            ));
        }
    }
开发者ID:usefulthink,项目名称:symfony,代码行数:29,代码来源:AbstractLayoutTest.php

示例6: __construct

 public function __construct($gsite, $entry)
 {
   parent::__construct($gsite, $entry);
   $content = $entry->content->xpath("descendant::xhtml:table/descendant::xhtml:div[@dir = 'ltr']");
   $dom = new DomDocument();
   $dom->loadHTML((string)$entry->content->div->children()->asXML());
   $this->conteudo = $dom->saveHTML();
   //$this->conteudo = (string)$entry->content->div->children()->asXML();
   $this->_remover_links_das_imagens_do_conteudo();
   $this->_remover_links_tocs();
 }
开发者ID:neves,项目名称:qi,代码行数:11,代码来源:webpage.php

示例7: convertUrls

 private function convertUrls()
 {
     $uri = phpUri::parse($this->url);
     foreach ($this->xpath->query('//img[@src]') as $el) {
         $el->setAttribute('src', $uri->join($el->getAttribute('src')));
     }
     foreach ($this->xpath->query('//a[@href]') as $el) {
         $el->setAttribute('href', $uri->join($el->getAttribute('href')));
     }
     $this->html = $this->is_xml ? $this->dom->saveXML() : $this->dom->saveHTML();
 }
开发者ID:byjg,项目名称:pgbrowser,代码行数:11,代码来源:PGPage.php

示例8: convert

 /**
  * Perform the conversion
  *
  * @param  string  Input json to convert
  * @param  array   Custom HTML to insert - array [{paragraph_num} => {Closure} (,{paragraph_num} => {Closure})]
  * @return string  HTML
  */
 public function convert($json, $customInserts = null)
 {
     $this->customInserts = $customInserts;
     if (($this->json = json_decode($json)) === null) {
         throw new Exceptions\NotTraversableException('The JSON provided is not valid');
     }
     // sections is *always* our first node
     if (!isset($this->json->sections)) {
         throw new Exceptions\InvalidStructureException('The JSON provided is not in a Carbon Editor format.');
     }
     $this->convertRecursive($this->json->sections);
     return trim($this->dom->saveHTML($this->dom->documentElement));
 }
开发者ID:candybanana,项目名称:carbon-json-to-html,代码行数:20,代码来源:Converter.php

示例9: bady2cdata

function bady2cdata($html, $xml)
{
    //Get XML params
    $dom = new DomDocument();
    $dom->preserveWhiteSpace = FALSE;
    $dom->loadHtml($html);
    $params = $dom->getElementsByTagName('body');
    foreach ($params as $k => $v) {
        $html = $v->nodeValue;
    }
    $params = $dom->getElementsByTagName('title');
    foreach ($params as $k => $v) {
        $title = $v->nodeValue;
    }
    $params = $dom->getElementsByTagName('meta');
    foreach ($params as $k => $v) {
        if ($v->getAttribute('name') == 'description') {
            $description = $v->getAttribute('content');
        }
        if ($v->getAttribute('name') == 'Author') {
            $author = $v->getAttribute('content');
        }
    }
    //Write to XML
    $dom = new DomDocument();
    $dom->preserveWhiteSpace = FALSE;
    $dom->loadXML($xml);
    $ModulePrefs = $dom->getElementsByTagName('ModulePrefs');
    foreach ($ModulePrefs as $prefs) {
        $prefs->setAttribute('title', $title);
        $prefs->setAttribute('description', $description);
        $prefs->setAttribute('author', $author);
    }
    $params = $dom->getElementsByTagName('Content');
    foreach ($params as $k => $v) {
        //echo $v->nodeValue;
        $v->nodeValue = $html;
    }
    $s = '<?xml version="1.0" encoding="UTF-8" ?>';
    $s .= $dom->saveHTML();
    return $s;
}
开发者ID:programmer,项目名称:montage,代码行数:42,代码来源:xml.php

示例10: onAfterRender

 function onAfterRender()
 {
     $db = JFactory::getDBO();
     if (JFactory::getApplication()->isAdmin()) {
         return;
     }
     if (JFactory::getApplication()->getCfg('sef') == 0) {
         return;
     }
     if (JRequest::getVar('tmpl') == 'component') {
         return;
     }
     if (JRequest::getVar('format', 'html') != 'html') {
         return;
     }
     $body = JResponse::getBody();
     $doc = new DomDocument("1.0");
     $doc->loadHTML($body);
     $xpath = new DomXPath($doc);
     $hrefs = $xpath->query("//a");
     foreach ($hrefs as $href) {
         $link = $href->getAttribute('href');
         if (JFactory::getURI()->isInternal($link) == false) {
             continue;
         }
         $link = substr($link, 1);
         if ($this->params->get('raw')) {
             $origurl = JoomSEF::_createUri(new JURI($link));
         } else {
             $origurl = JoomSEF::getNonSEFURL($link);
         }
         if (strlen($origurl)) {
             $href->setAttribute('class', 'link_tip');
             $href->setAttribute('title', $origurl);
         }
     }
     $body = $doc->saveHTML();
     JResponse::setBody($body);
 }
开发者ID:ranrolls,项目名称:ras-full-portal,代码行数:39,代码来源:joomsefurl.php

示例11: function

          }

          var proxied = window.XMLHttpRequest.prototype.open;
          window.XMLHttpRequest.prototype.open = function() {
              if (arguments[1] !== null && arguments[1] !== undefined) {
                var url = arguments[1];
                url = rel2abs("' . $url . '", url);
                url = "' . PROXY_PREFIX . '" + url;
                arguments[1] = url;
              }
              return proxied.apply(this, [].slice.call(arguments));
          };

        }

      })();');
        $scriptElem->setAttribute("type", "text/javascript");
        $prependElem->insertBefore($scriptElem, $prependElem->firstChild);
    }
    echo "<!-- Proxified page constructed by miniProxy -->\n" . $doc->saveHTML();
} else {
    if (stripos($contentType, "text/css") !== false) {
        //This is CSS, so proxify url() references.
        echo proxifyCSS($responseBody, $url);
    } else {
        //This isn't a web page or CSS, so serve unmodified through the proxy with the correct headers (images, JavaScript, etc.)
        header("Content-Length: " . strlen($responseBody));
        echo $responseBody;
    }
}
开发者ID:amirpouya,项目名称:miniProxy,代码行数:30,代码来源:miniProxy.php

示例12: DomDocument

 function html_balance($html, $remove_empty = true)
 {
     if (!extension_loaded('dom')) {
         return $html;
     }
     if (!trim($html)) {
         return $html;
     }
     $doc = new DomDocument();
     $xhtml = '<?xml encoding="utf-8"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>' . "<div>{$html}</div>";
     $doc->encoding = 'utf-8';
     $doc->preserveWhitespace = false;
     $doc->recover = true;
     if (false === @$doc->loadHTML($xhtml)) {
         return $html;
     }
     if ($remove_empty) {
         // Remove empty nodes
         $xpath = new DOMXPath($doc);
         static $eE = array('area' => 1, 'br' => 1, 'col' => 1, 'embed' => 1, 'hr' => 1, 'img' => 1, 'input' => 1, 'isindex' => 1, 'param' => 1);
         do {
             $done = true;
             $nodes = $xpath->query('//*[not(text()) and not(node())]');
             foreach ($nodes as $n) {
                 if (isset($eE[$n->nodeName])) {
                     continue;
                 }
                 $n->parentNode->removeChild($n);
                 $done = false;
             }
         } while (!$done);
     }
     static $phpversion;
     if (!isset($phpversion)) {
         $phpversion = phpversion();
     }
     $body = $doc->getElementsByTagName('body');
     if (!$body->length) {
         return $html;
     }
     if ($phpversion > '5.3.6') {
         $html = $doc->saveHTML($doc->getElementsByTagName('body')->item(0)->firstChild);
     } else {
         $html = $doc->saveHTML();
         $html = preg_replace('`^<!DOCTYPE.+?>|<\\?xml .+?>|</?html>|</?body>|</?head>|<meta .+?/?>`', '', $html);
         # <?php
     }
     return preg_replace('`^<div>|</div>$`', '', trim($html));
 }
开发者ID:gizur,项目名称:osticket,代码行数:49,代码来源:class.format.php

示例13: exportThumbnailPage

function exportThumbnailPage()
{
    global $CONFIG;
    $album = $_GET['album'];
    $page = $_GET['page'];
    $path = $_GET['path'];
    $filename = "thumbnails.php";
    include $filename;
    $contents = ob_get_contents();
    ob_end_clean();
    $pictures = cpg_db_query("SELECT pid,title,filename,filepath FROM {$CONFIG['TABLE_PICTURES']} WHERE `aid` = '{$album}'");
    $picture_r = array();
    while ($picture = mysql_fetch_array($pictures)) {
        $picture_r[$picture['pid']] = $picture['filepath'] . $picture['filename'];
    }
    // Create a DOM Object to parse the html (Removing links to dynamic content/functions that require php)
    $doc = new DomDocument();
    $doc->loadHtml($contents);
    $divs = $doc->getElementsByTagName('div');
    foreach ($divs as $div) {
        if ($div->getAttribute('id') == 'MENUS' || $div->getAttribute('class') == 'admin_menu_wrapper') {
            $div->setAttribute('style', 'display:none');
        }
    }
    $tds = $doc->getElementsByTagName('td');
    foreach ($tds as $td) {
        if ($td->getAttribute('class') == 'sortorder_options') {
            $td->setAttribute('style', 'display:none');
        }
    }
    $contents = $doc->saveHTML();
    foreach ($picture_r as $id => $filename) {
        $contents = preg_replace("/displayimage.php\\?album={$album}&amp;pid={$id}/", "albums/{$filename}", $contents);
    }
    $contents = preg_replace("/thumbnails.php\\?album=2&amp;page=([\\d]+)/", 'thumbnails_$1.html', $contents);
    // Find out the theme currently used and copy over necessary files to replicate this
    $result = cpg_db_query("SELECT value FROM {$CONFIG['TABLE_CONFIG']} WHERE `name` = 'theme'");
    $theme = mysql_fetch_array($result);
    recursive_copy("themes/{$theme['value']}", "{$path}/themes/{$theme['value']}");
    file_put_contents("{$path}/thumbnails_{$page}.html", $contents);
    if ($page == 1) {
        copy("{$path}/thumbnails_{$page}.html", "{$path}/index.html");
    }
}
开发者ID:phill104,项目名称:branches,代码行数:44,代码来源:export.php

示例14: rework_navigation

 public function rework_navigation(Block $block)
 {
     $h = $block->header;
     $b = $block->body;
     $i = $block->id;
     $dom = new DomDocument();
     $dom->loadHTML($b);
     $output = array();
     $html = "<section id='{$i}'>\n<nav class='mdl-navigation'>\n";
     foreach ($dom->getElementsByTagName('a') as $item) {
         $item->setAttribute('class', 'mdl-navigation__link');
         $html .= $dom->saveHTML($item);
         //  $output[] = array (
         //     ,'str' => $dom->saveHTML($item)
         //     // ,'href' => $item->getAttribute('href')
         //     // ,'anchorText' => $item->nodeValue
         //  );
     }
     $html .= "</nav>\n</section>\n";
     return $html;
 }
开发者ID:CrandellWS,项目名称:shimmie2,代码行数:21,代码来源:layout.class.php

示例15: _boinc_firstlink

function _boinc_firstlink(&$alink)
{
    if (!empty($alink)) {
        $dom = new DomDocument();
        $dom->loadHTML($alink);
        $myli = $dom->getElementsByTagName('li');
        if ($myli->length > 0) {
            $newclasses = trim($myli[0]->getAttribute("class") . " first");
            $myli[0]->setAttribute("class", $newclasses);
            $alink = $dom->saveHTML($myli[0]);
        }
    }
}
开发者ID:gchilders,项目名称:boinc,代码行数:13,代码来源:template.php


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