當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。