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


PHP DOMDocument::createCDataSection方法代码示例

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


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

示例1: format

 /**
  * Formats data into a single line to be written by the writer
  *
  * @param array $event
  * @return string
  */
 public function format($event)
 {
     if ($this->_elementMap === null) {
         $dataToInsert = $event;
     } else {
         $dataToInsert = array();
         foreach ($this->_elementMap as $elementName => $fieldKey) {
             $dataToInsert[$elementName] = $event[$fieldKey];
         }
     }
     $dom = new DOMDocument();
     $elt = $dom->appendChild(new DOMElement($this->_rootElement));
     foreach ($dataToInsert as $key => $value) {
         if ($key == "message") {
             $value = $value['message'];
             $message = $elt->appendChild(new DOMElement('email'));
             foreach (array('headers', 'body') as $messageKey) {
                 $value[$messageKey] = str_replace('=3D', '=', $value[$messageKey]);
                 $value[$messageKey] = str_replace(Zend_Mime::$qpReplaceValues, Zend_Mime::$qpKeys, $value[$messageKey]);
                 $elem = $message->appendChild(new DomElement($messageKey));
                 $elem->appendChild($dom->createCDataSection($value[$messageKey]));
             }
             $elt->appendChild($message);
         } else {
             $elt->appendChild(new DOMElement($key, $value));
         }
     }
     $dom->formatOutput = true;
     $xml = $dom->saveXML();
     $xml = preg_replace('/<\\?xml version="1.0"( encoding="[^\\"]*")?\\?>\\n/u', '', $xml);
     return $xml . PHP_EOL;
 }
开发者ID:robzienert,项目名称:Drake,代码行数:38,代码来源:Formatter.php

示例2: saveAction

 public function saveAction()
 {
     if ($data = Zend_Json::decode($this->getRequest()->getRawBody())) {
         try {
             $base_path = Core_Model_Directory::getBasePathTo("languages" . DS);
             $country_code = $data["country_code"];
             $translation_dir = $base_path . $country_code;
             $translation_file = $data["file"];
             $translation_datas = $data["collection"];
             ksort($translation_datas);
             if (empty($country_code)) {
                 throw new Exception($this->_("Please, choose a language."));
             }
             if (empty($translation_file)) {
                 throw new Exception($this->_("Please, choose a file."));
             }
             //android translations
             $pathinfo = pathinfo($translation_file);
             if (!empty($pathinfo["extension"]) and $pathinfo["extension"] == "xml") {
                 $base_path = $this->_xml_files[$translation_file]["base_path"];
                 $default_translation_dir = $base_path;
                 $translation_dir = $this->_xml_files[$translation_file]["user_path"] . "values-" . Core_Model_Lib_String::formatLanguageCodeForAndroid($country_code) . DS;
                 $translation_file = $this->_xml_files[$translation_file]["file_name"];
                 if (!is_dir($translation_dir)) {
                     mkdir($translation_dir);
                 }
                 $xml = new DOMDocument();
                 $xml->load($default_translation_dir . $translation_file);
                 foreach ($translation_datas as $key => $value) {
                     $modified_key = str_replace(" ", "_", strtolower(trim(current(explode("(", $key)))));
                     foreach ($xml->getElementsByTagName("string") as $node) {
                         if (empty($value) && $node->getAttribute("name") == $modified_key || stripos($node->nodeValue, '{#--') !== false) {
                             $node->parentNode->removeChild($node);
                             continue;
                         }
                         if ($node->getAttribute("name") == $modified_key) {
                             $cdata = $xml->createCDataSection(addslashes($value));
                             $node->nodeValue = "";
                             $node->appendChild($cdata);
                         }
                     }
                 }
                 $xml->save($translation_dir . $translation_file);
             } else {
                 if (!is_dir($translation_dir)) {
                     mkdir($translation_dir);
                 }
                 $ressource = fopen($translation_dir . DS . $translation_file, "w");
                 foreach ($translation_datas as $key => $value) {
                     if (empty($value)) {
                         continue;
                     }
                     $this->_putCsv($ressource, array($key, $value));
                 }
                 fclose($ressource);
                 if (!file_exists($translation_dir . DS . "default.csv")) {
                     $ressource = fopen($translation_dir . DS . "default.csv", "w");
                     $this->_putCsv($ressource, array("", ""));
                     fclose($ressource);
                 }
             }
             $data = array("success" => 1, "message" => $this->_("Language successfully saved"));
         } catch (Exception $e) {
             $data = array("error" => 1, "message" => $e->getMessage());
         }
         $this->_sendHtml($data);
     }
 }
开发者ID:bklein01,项目名称:siberian_cms_2,代码行数:68,代码来源:EditController.php

示例3: __toString

 public function __toString()
 {
     $doc = new DOMDocument();
     $doc->loadXML('<doc/>');
     foreach ($this->fieldnames as $fieldname) {
         foreach ($this->data[$fieldname] as $value) {
             $node = $doc->documentElement->appendChild($doc->createElement('field'));
             $htmlSafeValue = htmlspecialchars($value);
             if ($htmlSafeValue == $value) {
                 $node->appendChild($doc->createTextNode($htmlSafeValue));
             } else {
                 $node->appendChild($doc->createCDataSection($value));
             }
             $node->setAttribute('name', $fieldname);
         }
     }
     return $doc->saveXml($doc->documentElement);
 }
开发者ID:rubensworks,项目名称:OpenSKOS,代码行数:18,代码来源:Document.php

示例4: createStringNode

 /**
  * given a value if it is null return null otherwise a DOMNode
  *
  * @param string $value
  * @param DOMDocument $doc
  * @return DOMNode | null
  */
 public function createStringNode($value, DOMDocument $doc)
 {
     return is_null($value) ? null : $doc->createCDataSection($value);
 }
开发者ID:sirishreddyg,项目名称:magento-retail-order-management,代码行数:11,代码来源:Pim.php

示例5: toXML

 /**
  * Serialize to XML
  *
  * @return DOMDocument
  */
 public function toXML()
 {
     if ($this->library_id == "") {
         throw new \Exception("Cannot access data, it has not been loaded");
     }
     $xml = new \DOMDocument();
     $xml->loadXML("<library />");
     $xml->documentElement->setAttribute("library_id", $this->library_id);
     $xml->documentElement->setAttribute("pz2_key", $this->pz2_key);
     foreach ($this->vars as $k => $v) {
         //$node = $xml->createElement($k, htmlentities($v));
         if (htmlentities($v) != $v) {
             $sect = $xml->createCDataSection($v);
             $node = $xml->createElement($k);
             $node->appendChild($sect);
         } else {
             $node = $xml->createElement($k, $v);
         }
         $xml->documentElement->appendChild($node);
     }
     return $xml;
 }
开发者ID:navtis,项目名称:xerxes-search25,代码行数:27,代码来源:Library.php


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