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


PHP Arrays::value_has_type方法代码示例

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


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

示例1: array

 /**
 	  ARRAY TO XML:  Usage example.
 	  v1 - 05/May/2008
 	 $a = array(
 		'title' => array(
 			'value'   => 'this is a section element with an id = title',
 			'tagname' => 'section' // the element will be <section id="title">this is a ...</section>
 		),
 		// same as above
 		'section' => array(
 			'value'	=> 'this is a section element with an id = title2',
 			'id'    => 'title2'
 		),
 		'metatags' => array(
 			'tagname' => 'section',
 			// if you want to declare several elements with the same tag use numbers
 			'meta'    => array(
 				0 => array(
 					'http-equiv' => 'content-language',
 					'content'    => 'es-mx',
 					'id'         => 'numbered'
 				),
 				1 => array(
 					'name'    => 'description',
 					// this will be added as attribute and all the html characters will be converted
 					'content' => 'Giro Diseño - Su mejor <a>opción</a> en el desarrollo web'
 				),
 				2 => array(
 					'value'  => 'text value',
 					'tagname' => 'othermeta' // this method of giving an id won't work and will be ignored
 				),
 				'a' => 'foo'  // this is invalid it will be removed
 			)
 		),
 		'content' => array(
 			'tagname' => 'section',
 			'value'   => '<h1>Ñ</h1><p>Hola Mundo! ñoño!</p>' // this will use CDATA
 		),
 		'tagname' => 'foo',		// this is invalid. it will be ignored
 		'value' => 'hola mundo' // this is invalid. it will be ignored
 	);
 	**/
 private static function _array2XML($array, $obj = false, $valid = false)
 {
     // if we want to enable formatoutput, we must generate valid XML.
     // so, we must prevent the creation of textcontent elements in the
     // same level as element nodes. ej: <element><otherelement />text content</element>
     // for this, we must prevent the array to have mixed values,
     // so, we check for arrays within arrays (element nodes) and if found something
     // remove all non array values (textcontent elements).
     // of course this could be expensive if we're dealing with large arrays
     // so this is disabled by default and it's only enabled if formatoutput is set to true
     if ($valid) {
         if (Arrays::value_has_type('array', $array)) {
             if ($naa = Arrays::value_get_type('!array', $array)) {
                 foreach ($naa as $k => $v) {
                     unset($array[$k]);
                 }
             }
         }
     }
     // start the normal inspection of the array
     foreach ($array as $key => $val) {
         $key = strtolower($key);
         // if value isn't array it means that this is a value or an attribute
         if (!is_array($val)) {
             $val = utf8_encode($val);
             // determine if the value must be enclosed with cdata;
             $cdata = false;
             if (htmlspecialchars($val) != $val) {
                 $cdata = true;
             }
             // if a tagname key is defined ignore it
             if ($key == 'tagname') {
                 continue;
             }
             // set the value if any
             if ($key == 'value') {
                 // if the value has specialchars use cdata instead of textnode
                 if ($cdata) {
                     $o = self::$_DOM->createCDATASection($val);
                 } else {
                     $o = self::$_DOM->createTextNode($val);
                 }
                 $obj->appendChild($o);
             } else {
                 $obj->setAttribute($key, $cdata ? htmlspecialchars($val) : $val);
             }
             // skip to the next key;
             continue;
         }
         // value is an array
         $tag = $key;
         $id = null;
         // if a tagname key exists, set it's value as an element name.
         // and store the key name as an id attribute, also, we uset the
         // tagname key so it doesn't interfere later.
         if (array_key_exists('tagname', $val)) {
             $tag = $val['tagname'];
             $id = $key;
//.........这里部分代码省略.........
开发者ID:hectormenendez,项目名称:h23,代码行数:101,代码来源:xml.php


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