本文整理汇总了PHP中DOMDocument::LoadHTML方法的典型用法代码示例。如果您正苦于以下问题:PHP DOMDocument::LoadHTML方法的具体用法?PHP DOMDocument::LoadHTML怎么用?PHP DOMDocument::LoadHTML使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DOMDocument
的用法示例。
在下文中一共展示了DOMDocument::LoadHTML方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: display_feed
/**
* Displays MailChimp feed.
*
* Most notably, it adds necessary inline styles to whip email templates into shape.
*
* @param string $content Post content.
* @return string Modified post content, specific to the MailChimp feed.
*/
public function display_feed($content)
{
$dom_util = WP_DOM_Util::get_instance();
$dom = new DOMDocument();
$dom->preserveWhiteSpace = false;
$dom->LoadHTML($dom_util->get_meta() . $content);
$images = $dom->getElementsByTagName('img');
foreach ($images as $image) {
$image->setAttribute('style', 'max-width: 100%;');
}
do_action('wp_mailchimp_feed_modify_dom', $dom);
$content = $dom_util->get_inner_html($dom->getElementsByTagName('body')->item(0));
return $content;
}
示例2: getFileFromChaudiere
/**
* Get file list from boiler
*
* @return json this list
*/
public function getFileFromChaudiere()
{
$r['response'] = true;
$htmlCode = file_get_contents('http://' . CHAUDIERE . URL);
$dom = new DOMDocument();
$dom->LoadHTML($htmlCode);
$links = $dom->GetElementsByTagName('a');
$t_href = array();
foreach ($links as $a) {
$href = $a->getAttribute('href');
if (preg_match("/csv/i", $href)) {
array_push($t_href, array("file" => trim(str_replace(URL . "/", "", $href)), "url" => 'http://' . CHAUDIERE . $href));
}
}
$r['listefiles'] = $t_href;
$this->sendResponse($r);
}
示例3: css_tricks_super_awesome_feed_image_magic
/**
* css_tricks_super_awesome_feed_image_magic. Nuff' Said!
*
* @since 1.0.0
* @access public
* @return string the feed content
*/
public function css_tricks_super_awesome_feed_image_magic($content)
{
// Weirdness we need to add to strip the doctype with later.
$content = '<div>' . $content . '</div>';
$doc = new DOMDocument();
$doc->LoadHTML($content);
$images = $doc->getElementsByTagName('img');
foreach ($images as $image) {
$image->removeAttribute('height');
$image->setAttribute('width', '320');
$image->setAttribute('style', 'display: block;');
}
$figures = $doc->getElementsByTagName('figure');
foreach ($figures as $figure) {
$figure->setAttribute('style', 'display: block; margin: 0 0 10px 0;');
}
$iframes = $doc->getElementsByTagName('iframe');
foreach ($iframes as $iframe) {
$iframe->parentNode->removeChild($iframe);
}
// Strip weird DOCTYPE that DOMDocument() adds in
$content = substr($doc->saveXML($doc->getElementsByTagName('div')->item(0)), 5, -6);
return $content;
}
示例4: wbw_super_awesome_feed_image_magic
function wbw_super_awesome_feed_image_magic($content)
{
// Weirdness we need to add to strip the doctype with later.
$content = '<div>' . $content . '</div>';
$doc = new DOMDocument();
$doc->LoadHTML($content);
$images = $doc->getElementsByTagName('img');
foreach ($images as $image) {
$image->removeAttribute('height');
$image->setAttribute('width', '556');
}
// Strip weird DOCTYPE that DOMDocument() adds in
$content = substr($doc->saveXML($doc->getElementsByTagName('div')->item(0)), 5, -6);
return $content;
}
示例5: get_image_elements
/**
* Gets the image DOM elements from content.
*
* @param string $content Content with some markup, usually post content.
* @return DOMNodeList List of image elements found in content.
*/
public function get_image_elements($content)
{
if (!empty($content)) {
$dom_util = WP_DOM_Util::get_instance();
$dom = new DOMDocument();
$dom->preserveWhiteSpace = false;
$dom->LoadHTML($dom_util->get_meta() . $content);
return $dom->getElementsByTagName('img');
}
return new DOMNodeList();
}
示例6: getPlayFabSiteStructureAsArray
function getPlayFabSiteStructureAsArray($link, $class)
{
// Get HTML
$pfdocs_client_content = file_get_contents($link);
$pfdocs_client_docref = new DOMDocument();
$pfdocs_client_docref->loadHTML($pfdocs_client_content);
// Get Method Block
$pfdocs_client_contentfinder = new DomXPath($pfdocs_client_docref);
$pfdocs_client_finderresult = $pfdocs_client_contentfinder->query("//*[@class='" . $class . "']");
if ($pfdocs_client_finderresult->length > 0) {
// Get Methods
$pfdocs_client_methods = $pfdocs_client_docref->saveHTML($pfdocs_client_finderresult->item(0));
$pfdocs_client_methods_docref = new DOMDocument();
$pfdocs_client_methods_docref->LoadHTML($pfdocs_client_methods);
$pfdocs_client_methods_contentfinder = new DOMXPath($pfdocs_client_methods_docref);
$pfdocs_client_methods_finderresult = $pfdocs_client_methods_contentfinder->evaluate("//li");
$pfdocs_client_methods_result = array();
foreach ($pfdocs_client_methods_finderresult as $entry) {
//$pfdocs_client_methods_result[] = '<' . $entry->tagName . '>' . $entry->nodeValue . '</' . $entry->tagName . '>';
// Save each methods raw HTML
$pfdocs_client_methods_result[] = $pfdocs_client_methods_docref->saveHTML($entry);
}
//print_r($pfdocs_client_methods_result);
//exit();
$pfdocs_client_docarray = array();
$temp_lastcathead = "";
$i = 0;
foreach ($pfdocs_client_methods_result as $rawentry) {
if (strpos($rawentry, "<div class=\"summary\">") == false) {
$temp_doc = new DOMDocument();
$temp_doc->loadHTML($rawentry);
$temp_heads = $temp_doc->getElementsByTagName('span')->item(0);
foreach ($temp_heads->childNodes as $temp_head) {
$temp_fcathead = $temp_doc->saveHTML($temp_head);
$temp_lastcathead = $temp_fcathead;
}
} else {
preg_match_all('/<a[^>]+href=([\'"])(.+?)\\1[^>]*>/i', $rawentry, $temp_link);
$temp_flink = $temp_link[2][0];
$temp_doc = new DOMDocument();
$temp_doc->loadHTML($rawentry);
$temp_heads = $temp_doc->getElementsByTagName('a')->item(0);
$temp_summs = $temp_doc->getElementsByTagName('div')->item(0);
foreach ($temp_heads->childNodes as $temp_head) {
$temp_fcat = $temp_doc->saveHTML($temp_head);
}
foreach ($temp_summs->childNodes as $temp_sum) {
$temp_fsum = $temp_doc->saveHTML($temp_sum);
}
$pfdocs_client_docarray[$temp_lastcathead][$i]['name'] = $temp_fcat;
$pfdocs_client_docarray[$temp_lastcathead][$i]['link'] = $temp_flink;
$pfdocs_client_docarray[$temp_lastcathead][$i]['sum'] = $temp_fsum;
$i++;
}
}
return $pfdocs_client_docarray;
}
}