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


PHP XML_Util::isValidName方法代码示例

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


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

示例1: _serializeArray

 /**
  * serialize an array
  *
  * @param array  &$array     array to serialize
  * @param string $tagName    name of the root tag
  * @param array  $attributes attributes for the root tag
  *
  * @return string $string serialized data
  * @access private
  * @uses XML_Util::isValidName() to check, whether key has to be substituted
  * @uses XML_Util::replaceEntities()
  * @uses XML_Util::createComment()
  * @uses PEAR::popExpect()
  * @uses PEAR::expectError()
  */
 function _serializeArray(&$array, $tagName = null, $attributes = array())
 {
     $_content = null;
     $_comment = null;
     // check for comment
     if ($this->options[XML_SERIALIZER_OPTION_COMMENT_KEY] !== null) {
         if (isset($array[$this->options[XML_SERIALIZER_OPTION_COMMENT_KEY]])) {
             $_comment = $array[$this->options[XML_SERIALIZER_OPTION_COMMENT_KEY]];
             unset($array[$this->options[XML_SERIALIZER_OPTION_COMMENT_KEY]]);
         }
     }
     /**
      * check for special attributes
      */
     if ($this->options[XML_SERIALIZER_OPTION_ATTRIBUTES_KEY] !== null) {
         if (isset($array[$this->options[XML_SERIALIZER_OPTION_ATTRIBUTES_KEY]])) {
             $attributes = $array[$this->options[XML_SERIALIZER_OPTION_ATTRIBUTES_KEY]];
             unset($array[$this->options[XML_SERIALIZER_OPTION_ATTRIBUTES_KEY]]);
         }
         /**
          * check for special content
          */
         if ($this->options[XML_SERIALIZER_OPTION_CONTENT_KEY] !== null) {
             if (isset($array[$this->options[XML_SERIALIZER_OPTION_CONTENT_KEY]])) {
                 $_content = XML_Util::replaceEntities($array[$this->options[XML_SERIALIZER_OPTION_CONTENT_KEY]]);
                 unset($array[$this->options[XML_SERIALIZER_OPTION_CONTENT_KEY]]);
             }
         }
     }
     if ($this->options[XML_SERIALIZER_OPTION_IGNORE_NULL] === true) {
         foreach (array_keys($array) as $key) {
             if (is_null($array[$key])) {
                 unset($array[$key]);
             }
         }
     }
     /*
      * if mode is set to simpleXML, check whether
      * the array is associative or indexed
      */
     if (is_array($array) && !empty($array) && $this->options[XML_SERIALIZER_OPTION_MODE] == XML_SERIALIZER_MODE_SIMPLEXML) {
         $indexed = true;
         foreach ($array as $key => $val) {
             if (!is_int($key)) {
                 $indexed = false;
                 break;
             }
         }
         if ($indexed && $this->options[XML_SERIALIZER_OPTION_MODE] == XML_SERIALIZER_MODE_SIMPLEXML) {
             $string = '';
             foreach ($array as $key => $val) {
                 $string .= $this->_serializeValue($val, $tagName, $attributes);
                 $string .= $this->options[XML_SERIALIZER_OPTION_LINEBREAKS];
                 // do indentation
                 if ($this->options[XML_SERIALIZER_OPTION_INDENT] !== null && $this->_tagDepth > 0) {
                     $string .= str_repeat($this->options[XML_SERIALIZER_OPTION_INDENT], $this->_tagDepth);
                 }
             }
             return rtrim($string);
         }
     }
     $scalarAsAttributes = false;
     if (is_array($this->options[XML_SERIALIZER_OPTION_SCALAR_AS_ATTRIBUTES]) && isset($this->options[XML_SERIALIZER_OPTION_SCALAR_AS_ATTRIBUTES][$tagName])) {
         $scalarAsAttributes = $this->options[XML_SERIALIZER_OPTION_SCALAR_AS_ATTRIBUTES][$tagName];
     } elseif ($this->options[XML_SERIALIZER_OPTION_SCALAR_AS_ATTRIBUTES] === true) {
         $scalarAsAttributes = true;
     }
     if ($scalarAsAttributes === true) {
         $this->expectError('*');
         foreach ($array as $key => $value) {
             if (is_scalar($value) && XML_Util::isValidName($key) === true) {
                 unset($array[$key]);
                 $attributes[$this->options[XML_SERIALIZER_OPTION_PREPEND_ATTRIBUTES] . $key] = $value;
             }
         }
         $this->popExpect();
     } elseif (is_array($scalarAsAttributes)) {
         $this->expectError('*');
         foreach ($scalarAsAttributes as $key) {
             if (!isset($array[$key])) {
                 continue;
             }
             $value = $array[$key];
             if (is_scalar($value) && XML_Util::isValidName($key) === true) {
                 unset($array[$key]);
//.........这里部分代码省略.........
开发者ID:retrogamer4ever,项目名称:php-tools,代码行数:101,代码来源:Serializer.php

示例2: _serializeArray

 /**
  * serialize an array
  *
  * @access   private
  * @param    array   $array       array to serialize
  * @param    string  $tagName     name of the root tag
  * @param    array   $attributes  attributes for the root tag
  * @return   string  $string      serialized data
  * @uses     XML_Util::isValidName() to check, whether key has to be substituted
  */
 function _serializeArray(&$array, $tagName = null, $attributes = array())
 {
     $_content = null;
     /**
      * check for special attributes
      */
     if ($this->options['attributesArray'] !== null) {
         if (isset($array[$this->options['attributesArray']])) {
             $attributes = $array[$this->options['attributesArray']];
             unset($array[$this->options['attributesArray']]);
         }
         /**
          * check for special content
          */
         if ($this->options['contentName'] !== null) {
             if (isset($array[$this->options['contentName']])) {
                 $_content = $array[$this->options['contentName']];
                 unset($array[$this->options['contentName']]);
             }
         }
     }
     /*
      * if mode is set to simpleXML, check whether
      * the array is associative or indexed
      */
     if (is_array($array) && $this->options['mode'] == 'simplexml') {
         $indexed = true;
         if (!count($array)) {
             $indexed = false;
         }
         foreach ($array as $key => $val) {
             if (!is_int($key)) {
                 $indexed = false;
                 break;
             }
         }
         if ($indexed && $this->options['mode'] == 'simplexml') {
             $string = '';
             foreach ($array as $key => $val) {
                 if ($this->options['beautifyFilelist'] && $tagName == 'dir') {
                     if (!isset($this->_curdir)) {
                         $this->_curdir = '';
                     }
                     $savedir = $this->_curdir;
                     if (isset($val['attribs'])) {
                         if ($val['attribs']['name'] == '/') {
                             $this->_curdir = '/';
                         } else {
                             if ($this->_curdir == '/') {
                                 $this->_curdir = '';
                             }
                             $this->_curdir .= '/' . $val['attribs']['name'];
                         }
                     }
                 }
                 $string .= $this->_serializeValue($val, $tagName, $attributes);
                 if ($this->options['beautifyFilelist'] && $tagName == 'dir') {
                     $string .= ' <!-- ' . $this->_curdir . ' -->';
                     if (empty($savedir)) {
                         unset($this->_curdir);
                     } else {
                         $this->_curdir = $savedir;
                     }
                 }
                 $string .= $this->options['linebreak'];
                 //	do indentation
                 if ($this->options['indent'] !== null && $this->_tagDepth > 0) {
                     $string .= str_repeat($this->options['indent'], $this->_tagDepth);
                 }
             }
             return rtrim($string);
         }
     }
     if ($this->options['scalarAsAttributes'] === true) {
         foreach ($array as $key => $value) {
             if (is_scalar($value) && XML_Util::isValidName($key) === true) {
                 unset($array[$key]);
                 $attributes[$this->options['prependAttributes'] . $key] = $value;
             }
         }
     }
     // check for empty array => create empty tag
     if (empty($array)) {
         $tag = array('qname' => $tagName, 'content' => $_content, 'attributes' => $attributes);
     } else {
         $this->_tagDepth++;
         $tmp = $this->options['linebreak'];
         foreach ($array as $key => $value) {
             //	do indentation
             if ($this->options['indent'] !== null && $this->_tagDepth > 0) {
//.........这里部分代码省略.........
开发者ID:prometheus-ev,项目名称:promdilps,代码行数:101,代码来源:v2.php

示例3: _serializeArray

 /**
  * serialize an array
  *
  * @access   private
  * @param    array   $array       array to serialize
  * @param    string  $tagName     name of the root tag
  * @param    array   $attributes  attributes for the root tag
  * @return   string  $string      serialized data
  * @uses     XML_Util::isValidName() to check, whether key has to be substituted
  */
 function _serializeArray(&$array, $tagName = null, $attributes = array())
 {
     /**
      * check for special attributes
      */
     if ($this->options['attributesArray'] !== null) {
         $_content = null;
         if (isset($array[$this->options['attributesArray']])) {
             $attributes = $array[$this->options['attributesArray']];
             unset($array[$this->options['attributesArray']]);
         }
         /**
          * check for special content
          */
         if ($this->options['contentName'] !== null) {
             if (isset($array[$this->options['contentName']])) {
                 $_content = $array[$this->options['contentName']];
                 unset($array[$this->options['contentName']]);
             }
         }
     }
     /*
      * if mode is set to simpleXML, check whether
      * the array is associative or indexed
      */
     if (is_array($array) && $this->options["mode"] == "simplexml") {
         $indexed = true;
         foreach ($array as $key => $val) {
             if (!is_int($key)) {
                 $indexed = false;
                 break;
             }
         }
         if ($indexed) {
             $string = "";
             foreach ($array as $key => $val) {
                 $string .= $this->_serializeValue($val, $tagName, $attributes);
                 $string .= $this->options["linebreak"];
                 //	do indentation
                 if ($this->options["indent"] !== null && $this->_tagDepth > 0) {
                     $string .= str_repeat($this->options["indent"], $this->_tagDepth);
                 }
             }
             return rtrim($string);
         }
     }
     if ($this->options["scalarAsAttributes"] === true) {
         foreach ($array as $key => $value) {
             if (is_scalar($value) && XML_Util::isValidName($key) === true) {
                 unset($array[$key]);
                 $attributes[$this->options["prependAttributes"] . $key] = $value;
             }
         }
     }
     // check for empty array => create empty tag
     if (empty($array)) {
         $tag = array("qname" => $tagName, "content" => $_content, "attributes" => $attributes);
     } else {
         $this->_tagDepth++;
         $tmp = $this->options["linebreak"];
         foreach ($array as $key => $value) {
             //	do indentation
             if ($this->options["indent"] !== null && $this->_tagDepth > 0) {
                 $tmp .= str_repeat($this->options["indent"], $this->_tagDepth);
             }
             //	copy key
             $origKey = $key;
             //	key cannot be used as tagname => use default tag
             $valid = XML_Util::isValidName($key);
             if (PEAR::isError($valid)) {
                 $key = $this->options["defaultTagName"];
             }
             $atts = array();
             if ($this->options["typeHints"] === true) {
                 $atts[$this->options["typeAttribute"]] = gettype($value);
                 if ($key !== $origKey) {
                     $atts[$this->options["keyAttribute"]] = (string) $origKey;
                 }
             }
             $tmp .= $this->_createXMLTag(array("qname" => $key, "attributes" => $atts, "content" => $value));
             $tmp .= $this->options["linebreak"];
         }
         $this->_tagDepth--;
         if ($this->options["indent"] !== null && $this->_tagDepth > 0) {
             $tmp .= str_repeat($this->options["indent"], $this->_tagDepth);
         }
         if (trim($tmp) === '') {
             $tmp = null;
         }
         $tag = array("qname" => $tagName, "content" => $tmp, "attributes" => $attributes);
//.........这里部分代码省略.........
开发者ID:automatweb,项目名称:automatweb_sales,代码行数:101,代码来源:Serializer.php


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