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


PHP domDocument::loadHtml方法代码示例

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


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

示例1: array

// ==============================================
// URL of project list
$url_module_usage_base_url = "http://drupal.org";
$url_module_usage = $url_module_usage_base_url . "/project/usage";
// get the list of all project names
echo "\nLoading project list ... ";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url_module_usage);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$html = curl_exec($ch);
curl_close($ch);
// Parsing the list in order to get more informations
$projects = array();
$dom = new domDocument();
@$dom->loadHtml($html);
$table = $dom->getElementById("project-usage-all-projects");
$rows = $table->getElementsByTagName("tr");
$cpt = 0;
foreach ($rows as $row) {
    $project = $row->getElementsByTagName('a')->item(0);
    $project_name = $project->nodeValue;
    $url = $url_module_usage_base_url . $project->getAttribute('href');
    $pos_slash = strrpos($url, "/");
    $project_id = substr($url, $pos_slash + 1);
    $projects[] = array("id" => $project_id, "name" => $project_name);
    if ($nb_modules_to_scan != 0 && count($projects) == $nb_modules_to_scan) {
        break;
    }
}
$nb_projects = count($projects);
开发者ID:ridick,项目名称:drupal-scan,代码行数:31,代码来源:drupal-scan.php

示例2: run

 public function run($str = nULL)
 {
     if (!is_null($str)) {
         $regex = '/<([a-z0-9\\-]+)(.*?)>(?:(.*?)(<\\/\\1>))?/ix';
         if (is_a($str, jqmel)) {
             $str = $str->dom()->get()->lastdom;
         } elseif (is_callable($str)) {
             $str = call_user_func($str, array());
         }
         $str = preg_replace('/\\s+/', ' ', $str);
         if (preg_match($regex, $str, $match)) {
             $match[2] = rtrim($match[2], '/');
         }
         $document = jqm_use($this->node->_parentElement);
         $np = $this->node->next()->get();
         $npp = $this->node->prev()->get();
         $par = $this->node->parent();
         $wrap = $str;
         if (!is_a($par->get(), jqmel)) {
             return;
         }
         $rec = $document->_DOM;
         if ($rec->doctype) {
             $rec->removeChild($rec->doctype);
         }
         $xpath = new domxpath($rec);
         $find = $xpath->query($this->node->_path);
         if ($find->length > 0) {
             $child = new domDocument();
             $child->loadHtml($wrap);
             if ($child->doctype) {
                 $child->removeChild($child->doctype);
             }
             $chf = $child->getElementsByTagName($match[1]);
             $node = $this->node->__toDomElement();
             $frag = $child->importNode($node, true);
             $depth = $this->getDeepest($chf->item(0));
             $save = $depth->appendChild($frag);
             //Import to document
             $frag = $rec->importNode($chf->item(0), true);
             $newsave = $find->item(0)->parentNode->replaceChild($frag, $find->item(0));
             $new_path = explode('/', $frag->getNodePath());
             $p_path = array_filter(explode('/', $save->getNodePath()));
             //$p_path = array_pop($p_path);
             $htm = array_search('html', $p_path);
             if ($htm) {
                 unset($p_path[$htm]);
                 unset($p_path[$htm + 1]);
             }
             $new_path = array_merge($new_path, $p_path);
             $sh = array_pop($new_path);
             array_pop($new_path);
             $ele_path = ltrim($newsave->getNodePath(), '/');
             $this->node->_parent_path = implode('/', $new_path);
             $this->node->_path = $this->node->_parent_path . '/' . $sh;
             $wrap = $rec->saveHtml($frag->parentNode);
             $wrap = substr($wrap, strpos($wrap, '>') + 1);
             if (!empty($par->get()->_localName)) {
                 $wrap = substr($wrap, 0, strripos($wrap, $par->get()->_localName));
                 $par->get()->html($wrap);
             }
             $find = $this->node->getPathById();
             if ($find) {
                 $this->node->_path = $find;
             }
             if ($this->node->trace) {
                 $key = $this->node->trace->key();
                 $this->node->trace->next();
                 $n = $this->node->trace->current();
                 if ($key > 0) {
                     $this->node->trace->seek($key - 1);
                     $p = $this->node->trace->current();
                 }
                 if ($p and is_a($p, jqmel)) {
                     $find = $p->getPathById();
                     if ($find) {
                         $p->_path = $find;
                         //var_dump($key,$p);
                     }
                 }
                 if ($n and is_a($n, jqmel)) {
                     $find = $n->getPathById();
                     if ($find) {
                         $n->_path = $find;
                     }
                 }
                 unset($p);
                 unset($n);
             }
         }
     }
 }
开发者ID:Webictbyleo,项目名称:JqueryPhp,代码行数:92,代码来源:wrap.php


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