本文整理汇总了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;
}
示例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(' ', ' ', $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;
}
示例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(' ', ' ', $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;
}