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


PHP DOMDocument::loadhtml方法代码示例

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


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

示例1: getCountries

 protected function getCountries()
 {
     $xe = $this->web->get(sfConfig::get('app_source_countries'), null, array('Cache-Control' => 'no-cache'));
     $doc = new DOMDocument();
     // It's rare you'll have valid XHTML, suppress any errors- it'll do its best.
     @$doc->loadhtml($xe->getResponseText());
     $xpath = new DOMXPath($doc);
     foreach ($xpath->query('/html/body//form//select[@name="From"]')->item(0)->getElementsByTagName('option') as $option) {
         $currency = Doctrine::getTable('Currency')->findOneByCode($option->getAttribute('value'));
         $name = substr($option->textContent, 0, strpos($option->textContent, ','));
         if ($currency instanceof Currency && !empty($name)) {
             $country = Doctrine::getTable('Country')->findOneByName($name);
             if (!$country instanceof Country) {
                 $country = new Country();
                 $country->setName($name);
             }
             $country->Currencies[] = $currency;
             $country->save();
         }
     }
 }
开发者ID:asaraf28,项目名称:CurrencyConverter,代码行数:21,代码来源:getCurrenciesTask.class.php

示例2: listen

 /**
  *	Receive ping, check if local page is pingback-enabled, verify
  *	source contents, and return XML-RPC response
  *	@return string
  *	@param $func callback
  *	@param $path string
  **/
 function listen($func, $path = NULL)
 {
     $fw = \Base::instance();
     if (PHP_SAPI != 'cli') {
         header('X-Powered-By: ' . $fw->get('PACKAGE'));
         header('Content-Type: application/xml; ' . 'charset=' . ($charset = $fw->get('ENCODING')));
     }
     if (!$path) {
         $path = $fw->get('BASE');
     }
     $web = \Web::instance();
     $args = xmlrpc_decode_request($fw->get('BODY'), $method, $charset);
     $options = array('encoding' => $charset);
     if ($method == 'pingback.ping' && isset($args[0], $args[1])) {
         list($source, $permalink) = $args;
         $doc = new \DOMDocument('1.0', $fw->get('ENCODING'));
         // Check local page if pingback-enabled
         $parts = parse_url($permalink);
         if ((empty($parts['scheme']) || $parts['host'] == $fw->get('HOST')) && preg_match('/^' . preg_quote($path, '/') . '/' . ($fw->get('CASELESS') ? 'i' : ''), $parts['path']) && $this->enabled($permalink)) {
             // Check source
             $parts = parse_url($source);
             if ((empty($parts['scheme']) || $parts['host'] == $fw->get('HOST')) && ($req = $web->request($source)) && $doc->loadhtml($req['body'])) {
                 $links = $doc->getelementsbytagname('a');
                 foreach ($links as $link) {
                     if ($link->getattribute('href') == $permalink) {
                         call_user_func_array($func, array($source, $req['body']));
                         // Success
                         die(xmlrpc_encode_request(NULL, $source, $options));
                     }
                 }
                 // No link to local page
                 die(xmlrpc_encode_request(NULL, 0x11, $options));
             }
             // Source failure
             die(xmlrpc_encode_request(NULL, 0x10, $options));
         }
         // Doesn't exist (or not pingback-enabled)
         die(xmlrpc_encode_request(NULL, 0x21, $options));
     }
     // Access denied
     die(xmlrpc_encode_request(NULL, 0x31, $options));
 }
开发者ID:eFiction,项目名称:v5_1-vaporware,代码行数:49,代码来源:pingback.php

示例3: LoadDomFromHTML

 public function LoadDomFromHTML($strHTML)
 {
     // $oDOM = new DOMDocument( '1.0', $this->strCharEncoding );
     $oDOM = new DOMDocument('1.0');
     // $oDOM->preserveWhiteSpace = false;
     // $oDOM->formatOutput = true;
     // $strHTML = '<div>' . $strHTML . '</div>';        // this prevents later when using saveXML() from inserting the comment <!-- xml version .... -->
     $oDOM->loadhtml($strHTML);
     return $oDOM;
 }
开发者ID:snickler,项目名称:Fetch-Tweets,代码行数:10,代码来源:FetchTweets_HTMLElementReplacer.php

示例4: changeLinks

 /**
  * Changes the links (src/href) of HTML
  * @return: String 
  */
 public function changeLinks($contents, $root_path = JPATH_ROOT, $base_uri = '')
 {
     /** change js links	**/
     $regex = '/src=(["\'])(.*?)\\1/';
     $count = preg_match_all($regex, $contents, $match);
     if ($count > 0) {
         $changes = $match[2];
         foreach ($changes as $change) {
             //remove url file not exists
             $uri = new JURI($change);
             if ($_SERVER['HTTP_HOST'] != $uri->getHost() && $uri->getHost() != '') {
                 $headers = @get_headers($change, 1);
                 if ($headers[0] == 'HTTP/1.1 404 Not Found') {
                     $contents = str_replace('src="' . $change . '"', 'src=""', $contents);
                 }
             }
         }
     }
     /** change href reference **/
     $regex = '/href=(["\'])(.*?)\\1/';
     $count = preg_match_all($regex, $contents, $match);
     if ($count > 0) {
         $changes = $match[2];
         foreach ($changes as $change) {
             //remove url file not exists
             $uri = new JURI($change);
             if ($_SERVER['HTTP_HOST'] != $uri->getHost() && $uri->getHost() != '') {
                 $headers = @get_headers($change, 1);
                 if ($headers[0] == 'HTTP/1.1 404 Not Found') {
                     $contents = str_replace('href="' . $change . '"', 'href=""', $contents);
                 }
             }
         }
     }
     /** change href reference **/
     $regex = '/action=(["\'])(.*?)\\1/';
     $count = preg_match_all($regex, $contents, $match);
     if ($count > 0) {
         $changes = $match[2];
         foreach ($changes as $change) {
             //remove url file not exists
             $uri = new JURI($change);
             if ($_SERVER['HTTP_HOST'] != $uri->getHost() && $uri->getHost() != '') {
                 $headers = @get_headers($change, 1);
                 if ($headers[0] == 'HTTP/1.1 404 Not Found') {
                     $contents = str_replace('action="' . $change . '"', 'action=""', $contents);
                 }
             }
         }
     }
     /** change links **/
     $doc = new DOMDocument();
     if (@$doc->loadhtml($contents)) {
         $xpath = new DOMXpath($doc);
         $uri = JURI::getInstance();
         foreach ($xpath->query('//html//a') as $eInput) {
             $href = $eInput->getAttribute('href');
             $uri = new JURI($href);
             if (JString::trim($href) != '#' && JString::trim($href) != '' && ($_SERVER['HTTP_HOST'] == $uri->getHost() || $uri->getHost() == '')) {
                 $extend_url = JSN_RENDER_PAGE_URL . base64_encode($href);
                 $eInput->setAttribute('href', $extend_url);
             } else {
                 $eInput->setAttribute('href', 'javascript:;');
             }
         }
     }
     /** SAVE HTML after changed **/
     return $doc->saveHTML();
 }
开发者ID:kleinhelmi,项目名称:tus03_j3_2015_01,代码行数:73,代码来源:poweradmin.php

示例5: getCurrentItemid

 /**
  * Get Current Menu Id.
  *
  * @return  integer
  */
 public function getCurrentItemid()
 {
     $doc = new DOMDocument();
     if (@$doc->loadhtml($this->_contents)) {
         $doc->preserveWhiteSpace = false;
         $component = $doc->getElementById('tableshow');
         if (is_object($component)) {
             return $component->getAttribute('itemid');
         }
     }
     return 0;
 }
开发者ID:jdrzaic,项目名称:joomla-dummy,代码行数:17,代码来源:render.php


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