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


PHP DomDocument::loadHtml方法代码示例

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


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

示例1: getDomObject

 private function getDomObject()
 {
     if ($this->_verbose > 2) {
         $this->log('IN:[' . __FUNCTION__ . ']', 0, "purple");
     }
     if ($this->_verbose > 1) {
         $this->log("Content length: " . strlen($this->_content), 0, "light_purple");
     }
     $DOM = new \DomDocument();
     switch ($this->_domType) {
         case "xml":
             if ($this->_verbose > 2) {
                 $this->log('<' . __LINE__ . '> DOMDocument->loadXML', 0, "purple");
             }
             @$DOM->loadXML($this->_content);
             break;
         case "html":
             if ($this->_verbose > 2) {
                 $this->log('<' . __LINE__ . '> DOMDocument->loadXML');
             }
             @$DOM->loadHtml($this->_content);
             break;
         default:
             throw new \Exception("Unknwon DOM type used to load content \"" . $this->_domType . "\"");
             break;
     }
     return $DOM;
 }
开发者ID:pthreat,项目名称:apf-dev,代码行数:28,代码来源:Dom.class.php

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

示例3: xpathQuery

 protected function xpathQuery($html, $xpath)
 {
     $dom = new \DomDocument();
     $dom->loadHtml($html);
     $domXpath = new \DomXPath($dom);
     return $domXpath->query($xpath);
 }
开发者ID:seanmorris,项目名称:theme,代码行数:7,代码来源:HtmlTestCase.php

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

示例5: testConvertsBoldTag

 public function testConvertsBoldTag()
 {
     $html = '<b>some text</b>';
     $doc = new \DomDocument();
     $doc->loadHtml($html);
     $tag = $doc->getElementsByTagName('b')->item(0);
     $parser = new \Markdownable\Tag\B();
     $this->assertSame($parser->parse($tag), '**some text**');
 }
开发者ID:progmedia,项目名称:markdownable,代码行数:9,代码来源:BTest.php

示例6: testConvertsPTag

 public function testConvertsPTag()
 {
     $html = '<p>A paragraph of text</p>';
     $doc = new \DomDocument();
     $doc->loadHtml($html);
     $tag = $doc->getElementsByTagName('p')->item(0);
     $parser = new \Markdownable\Tag\P();
     $this->assertSame($parser->parse($tag), PHP_EOL . PHP_EOL . 'A paragraph of text' . PHP_EOL);
 }
开发者ID:progmedia,项目名称:markdownable,代码行数:9,代码来源:PTest.php

示例7: testConvertsEmTag

 public function testConvertsEmTag()
 {
     $html = '<em>text</em>';
     $doc = new \DomDocument();
     $doc->loadHtml($html);
     $tag = $doc->getElementsByTagName('em')->item(0);
     $parser = new \Markdownable\Tag\Em();
     $this->assertSame($parser->parse($tag), '*text*');
 }
开发者ID:progmedia,项目名称:markdownable,代码行数:9,代码来源:EmTest.php

示例8: testConvertsHtmlBrTag

 public function testConvertsHtmlBrTag()
 {
     $html = '<br>';
     $doc = new \DomDocument();
     $doc->loadHtml($html);
     $tag = $doc->getElementsByTagName('br')->item(0);
     $parser = new \Markdownable\Tag\Br();
     $this->assertSame($parser->parse($tag), PHP_EOL);
 }
开发者ID:progmedia,项目名称:markdownable,代码行数:9,代码来源:BrTest.php

示例9: testConvertsAnchorTagWithTitle

 public function testConvertsAnchorTagWithTitle()
 {
     $html = '<a href="http://example.com" title="A Link">link</a>';
     $doc = new \DomDocument();
     $doc->loadHtml($html);
     $tag = $doc->getElementsByTagName('a')->item(0);
     $parser = new \Markdownable\Tag\A();
     $this->assertSame($parser->parse($tag), '[link](http://example.com "A Link")');
 }
开发者ID:progmedia,项目名称:markdownable,代码行数:9,代码来源:ATest.php

示例10: testConvertsImgTagWithTitle

 public function testConvertsImgTagWithTitle()
 {
     $html = '<img src="img.png" alt="alt text" title="An Image" />';
     $doc = new \DomDocument();
     $doc->loadHtml($html);
     $tag = $doc->getElementsByTagName('img')->item(0);
     $parser = new \Markdownable\Tag\Img();
     $this->assertSame($parser->parse($tag), '![alt text](img.png "An Image")');
 }
开发者ID:progmedia,项目名称:markdownable,代码行数:9,代码来源:ImgTest.php

示例11: testConvertsH6Tag

 public function testConvertsH6Tag()
 {
     $html = '<h6>Header 6</h6>';
     $doc = new \DomDocument();
     $doc->loadHtml($html);
     $tag = $doc->getElementsByTagName('h6')->item(0);
     $parser = new \Markdownable\Tag\H6();
     $this->assertSame($parser->parse($tag), PHP_EOL . PHP_EOL . '###### Header 6' . PHP_EOL . PHP_EOL);
 }
开发者ID:progmedia,项目名称:markdownable,代码行数:9,代码来源:HeaderTest.php

示例12: parseAttributes

 /**
  * Parse te given XML attributes into an array
  *
  * @author troelskn
  * @link http://stackoverflow.com/a/1083821/172068
  * @param $input
  * @return array
  */
 public function parseAttributes($input)
 {
     $dom = new DomDocument();
     $dom->loadHtml("<html {$input} />");
     $attributes = array();
     foreach ($dom->documentElement->attributes as $name => $attr) {
         $attributes[$name] = $attr->value;
     }
     return $attributes;
 }
开发者ID:xudianyang,项目名称:wiki.phpboy.net,代码行数:18,代码来源:helper.php

示例13: getDataFromFeed

function getDataFromFeed($url)
{
    $data = apc_fetch($url);
    if (!$data) {
        error_log('CACHE MISS: ' . $url);
        $data = file_get_contents($url);
        apc_store($url, $data, 600);
    }
    $doc = new DomDocument();
    @$doc->loadHtml($data);
    return $doc;
}
开发者ID:NeilCrosby,项目名称:biggeekdayout,代码行数:12,代码来源:refresh.php

示例14: extract

 /**
  * Extracts information from the file $fileName associated with the url $url.
  *
  * The document type for this document is given in $type, and the images on
  * disk should be in the directory named $imagePath. The urls where the
  * images link to should be in $imageUrlPath.
  *
  * @param string $fileName
  * @param string $type
  * @param string $url
  * @param string $imagePath
  * @param string $imageUrlPath
  * @return array(ezcSearchDocument)
  */
 public static function extract($fileName, $type, $url, $imagePath = null, $imageUrlPath = null)
 {
     $published = filemtime($fileName);
     $converted = file_get_contents($fileName);
     $dom = new DomDocument();
     @$dom->loadHtml($converted);
     $tbody = $dom->getElementsByTagName('div')->item(0);
     $xpath = new DOMXPath($dom);
     $tocElem = $xpath->evaluate("//h1[@class='title']", $tbody)->item(0);
     $title = $tocElem ? $tocElem->nodeValue : 'no title';
     $docs = array();
     $body = $urls = array();
     $currentUrl = $url;
     $lastUrl = $url;
     $currentBody = '';
     // child::*[self::p or self::h1]
     $xpath = new DOMXPath($dom);
     $tbody = $xpath->evaluate("//p|//h1|//ol|//ul|//dl|//img|//a", $tbody);
     $body = '';
     foreach ($tbody as $item) {
         switch ($item->tagName) {
             case 'a':
                 $name = $item->getAttribute('name');
                 if (strlen($name)) {
                     $currentUrl = $url . '#' . $name;
                 }
                 break;
             case 'img':
                 $alt = $item->getAttribute('alt');
                 $src = $item->getAttribute('src');
                 $location = $imagePath == null ? dirname($fileName) . '/' . $src : $imagePath . '/' . preg_replace('@(\\.\\./)+@', '', $src);
                 $imgurl = $src[0] == '/' ? $src : ($imageUrlPath === null ? $url . '/' . $src : $imageUrlPath . '/' . preg_replace('@(\\.\\./)+@', '', $src));
                 echo "  - {$src} => {$imgurl}\n";
                 $docs[] = self::extractImage($alt, $location, $imgurl);
                 break;
             case 'p':
             case 'h1':
             case 'dl':
                 if ($lastUrl !== $currentUrl) {
                     $docs[] = new ezcSearchSimpleArticle(null, $title, $currentBody, $published, $lastUrl, $type);
                     $currentBody = '';
                     $lastUrl = $currentUrl;
                 }
                 $currentBody .= strip_tags($dom->saveXml($item)) . "\n\n";
                 break;
         }
     }
     if ($currentBody != '') {
         $docs[] = new ezcSearchSimpleArticle(null, $title, $currentBody, $published, $lastUrl, $type);
     }
     return $docs;
 }
开发者ID:bmdevel,项目名称:ezc,代码行数:66,代码来源:rstxml.php

示例15: getDataFromHtml

 function getDataFromHtml($url)
 {
     $ignoreCache = isset($_GET['ignore_cache']);
     $data = apc_fetch($url);
     if (!$data || $ignoreCache) {
         error_log('CACHE MISS: ' . $url);
         $data = file_get_contents($url);
         apc_store($url, $data, 600);
     }
     $doc = new DomDocument();
     @$doc->loadHtml($data);
     return $doc;
 }
开发者ID:NeilCrosby,项目名称:lifestream,代码行数:13,代码来源:DataReader.php


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