本文整理汇总了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();
}
示例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());
}
示例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));
}
示例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);
}
示例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)
));
}
}
示例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();
}
示例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();
}
示例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));
}
示例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;
}
示例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);
}
示例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;
}
}
示例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));
}
示例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}&pid={$id}/", "albums/{$filename}", $contents);
}
$contents = preg_replace("/thumbnails.php\\?album=2&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");
}
}
示例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;
}
示例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]);
}
}
}