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


PHP Zend_Dom_Query::setDocumentXml方法代码示例

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


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

示例1: deleteBasePathUrl

 /**
  * Removes the base path of the URL to HTML resources
  *
  * @param string $html
  * @return string|bool If error, then output FALSE
  */
 protected function deleteBasePathUrl($html)
 {
     //$domHtml
     $str_begin = '<?xml version="1.0" encoding="utf-8"?>' . "\n" . '<body>';
     $str_end = '</body>';
     //---------------------------
     $filtrHtmlEntities = new Default_Form_Filter_HtmlEntities();
     $html = $filtrHtmlEntities->filter($html);
     $html = $str_begin . $html . $str_end;
     // Check for correct XML
     $domDoc = new DOMDocument('1.0', 'utf-8');
     $success = $domDoc->loadXML($html);
     if (!$success) {
         return FALSE;
     }
     // Correct code
     $domQuery = new Zend_Dom_Query();
     $domQuery->setDocumentXml($html, "utf-8");
     foreach (self::$tags as $tag => $attr) {
         $results = $domQuery->query($tag);
         if ($results->count()) {
             foreach ($results as $result) {
                 // $result variable is of DOMElement type
                 if ($result->hasAttribute($attr)) {
                     $value = $result->getAttribute($attr);
                     $st = new Default_Plugin_String($value);
                     if ($st->beginsWith('/')) {
                         // it was: /zf-myblog/public/pic/1.gif
                         // it is: /pic/1.gif
                         $baseURL = Default_Plugin_SysBox::getBaseURL();
                         $value = str_replace($baseURL, '', $value);
                         $result->setAttribute($attr, $value);
                     } else {
                         // it was: https://mysite.com:8080/zf-myblog/public/pic/1.gif
                         // it is: /pic/1.gif
                         $hostPortBaseURL = Default_Plugin_SysBox::getHostPortBaseURL();
                         $value = str_replace($hostPortBaseURL, '', $value);
                         $result->setAttribute($attr, $value);
                     }
                 }
             }
             $domDoc = $results->getDocument();
             $html = $domDoc->saveXml();
             $domQuery->setDocumentXml($html, "utf-8");
         }
     }
     $html = str_replace($str_begin, '', $html);
     $html = str_replace($str_end, '', $html);
     return $html;
 }
开发者ID:bsa-git,项目名称:zf-myblog,代码行数:56,代码来源:DeleteBasePathUrl.php

示例2: addBasePathUrl

 /**
  * add the base path to the URL of HTML Resources
  *
  * @param string $html
  * @return string
  */
 protected function addBasePathUrl($html)
 {
     //$domHtml
     $str_begin = '<?xml version="1.0" encoding="utf-8"?>' . "\n" . '<body>';
     $str_end = '</body>';
     //---------------------------
     $html = str_replace('&nbsp;', '&#160;', $html);
     $html = $str_begin . $html . $str_end;
     // Check for correct XML
     $domDoc = new DOMDocument('1.0', 'utf-8');
     $success = $domDoc->loadXML($html);
     if (!$success) {
         return FALSE;
     }
     $domQuery = new Zend_Dom_Query();
     $domQuery->setDocumentXml($html, "utf-8");
     foreach (self::$tags as $tag => $attr) {
         $results = $domQuery->query($tag);
         if ($results->count()) {
             foreach ($results as $result) {
                 // $result variable is of DOMElement type
                 if ($result->hasAttribute($attr)) {
                     $value = $result->getAttribute($attr);
                     $st = new Default_Plugin_String($value);
                     if ($st->beginsWith('/')) {
                         $baseURL = Default_Plugin_SysBox::getUrlRes($value);
                         $result->setAttribute($attr, $baseURL);
                     }
                 }
             }
             $domDoc = $results->getDocument();
             $html = $domDoc->saveXml();
             $domQuery->setDocumentXml($html, "utf-8");
         }
     }
     $html = str_replace($str_begin, '', $html);
     $html = str_replace($str_end, '', $html);
     return $html;
 }
开发者ID:bsa-git,项目名称:zf-myblog,代码行数:45,代码来源:AddBasePathUrl.php

示例3: getPHPInfo

 static function getPHPInfo()
 {
     $str_xml_begin = '<?xml version="1.0" encoding="utf-8"?>';
     //---------------------------
     // Получить инф. о PHP
     ob_start();
     phpinfo();
     $info = ob_get_contents();
     ob_end_clean();
     // Создадим обьект парсера
     // и получим содержание тега <BODY>...</BODY>
     $obj = new Default_Plugin_Domparser();
     $obj->setUrl($obj, $info);
     $info = $obj->getBody();
     // Получим строку в формате XML
     $html = $str_xml_begin . $info;
     $html = str_replace('&nbsp;', '&#160;', $html);
     //Проверка на корректость XML
     $domDoc = new DOMDocument('1.0', 'utf-8');
     $success = $domDoc->loadXML($html);
     if (!$success) {
         return self::Translate('Ошибка документа - DOM') . '!';
     }
     // Создадим новый документ
     $domNew = new Default_Plugin_DomBox('1.0', 'utf-8');
     // Добавим корневой тег
     $root = $domNew->createElement('div');
     $root->setAttribute('class', 'report-content');
     $root = $domNew->appendChild($root);
     // Найдем нужную инф-ию и вставим ее в новый документ
     $domQuery = new Zend_Dom_Query();
     $domQuery->setDocumentXml($html, "utf-8");
     // Заменим сетевые адреса изображений на локальные адреса
     $images = $domQuery->query('img');
     $count = $images->count();
     if ($count) {
         foreach ($images as $image) {
             $alt = $image->getAttribute('alt');
             if ($alt == 'PHP Logo') {
                 $url = self::getFullURL_Res('/images/system/PHPLogo.gif');
                 $image->setAttribute('src', $url);
             }
             if ($alt == 'Zend logo') {
                 $url = self::getFullURL_Res('/images/system/ZendLogo.gif');
                 $image->setAttribute('src', $url);
             }
         }
     }
     $domDoc = $images->getDocument();
     $html = $domDoc->saveXml();
     $domQuery->setDocumentXml($html, "utf-8");
     // Обернем таблицы в DIV и установим некоторые атрибуты
     $listElements = $domQuery->query('div.center > *');
     $count = $listElements->count();
     $count_tables = 10;
     foreach ($listElements as $el) {
         $nodeName = $el->nodeName;
         // Если это таблица обернем ее в DIV
         if ($nodeName == 'table') {
             if ($count_tables > 0) {
                 $count_tables--;
             }
             $el->setAttribute('width', '100%');
             $tableContainer = $domNew->createElement('div');
             $tableContainer->setAttribute('class', 'table-container');
             $tableContainer = $root->appendChild($tableContainer);
             $domNew->appendChilds($tableContainer, $el);
         } else {
             $domNew->appendChilds($root, $el);
         }
     }
     $html = $domNew->saveXML();
     $html = str_replace($str_xml_begin, '', $html);
     return $html;
 }
开发者ID:bsa-git,项目名称:zf-myblog,代码行数:75,代码来源:SysBox.php


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