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


PHP XML_serialize函数代码示例

本文整理汇总了PHP中XML_serialize函数的典型用法代码示例。如果您正苦于以下问题:PHP XML_serialize函数的具体用法?PHP XML_serialize怎么用?PHP XML_serialize使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: XML_serialize

function & XML_serialize($data, $level = 0, $prior_key = NULL){
	if($level == 0){ ob_start(); echo '<?xml version="1.0" ?>',"\n"; }
	while(list($key, $value) = each($data))
		if(!strpos($key, ' attr')) #if it's not an attribute
			#we don't treat attributes by themselves, so for an empty element
			# that has attributes you still need to set the element to NULL

			if(is_array($value) and array_key_exists(0, $value)){
				XML_serialize($value, $level, $key);
			}else{
				$tag = $prior_key ? $prior_key : $key;
				echo str_repeat("\t", $level),'<',$tag;
				if(array_key_exists("$key attr", $data)){ #if there's an attribute for this element
					while(list($attr_name, $attr_value) = each($data["$key attr"]))
						echo ' ',$attr_name,'="',thtmlspecialchars($attr_value),'"';
					reset($data["$key attr"]);
				}

				if(is_null($value)) echo " />\n";
				elseif(!is_array($value)) echo '>',thtmlspecialchars($value),"</$tag>\n";
				else echo ">\n",XML_serialize($value, $level+1),str_repeat("\t", $level),"</$tag>\n";
			}
	reset($data);
	if($level == 0){ $str = &ob_get_contents(); ob_end_clean(); return $str; }
}
开发者ID:pf5512,项目名称:phpstudy,代码行数:25,代码来源:alipay.function.php

示例2: XML_serialize

function XML_serialize(&$data, $encoding, $level = 0, $prior_key = NULL)
{
    if ($level == 0) {
        ob_start();
        echo '<?xml version="1.0"';
        if (empty($encoding) === false) {
            echo ' encoding="' . $encoding . '"';
        }
        echo '?>', "\n";
    }
    foreach ($data as $key => $value) {
        $is_cdata = false;
        if (!strpos($key, ' attr')) {
            #if it's not an attribute
            #we don't treat attributes by themselves, so for an empty element
            # that has attributes you still need to set the element to NULL
            if (is_array($value) and array_key_exists(0, $value)) {
                XML_serialize($value, $encoding, $level, $key);
            } else {
                $tag = $prior_key ? $prior_key : $key;
                if (($pos = strpos($tag, '-CDATA')) !== false) {
                    $tag = substr($tag, 0, $pos);
                    $is_cdata = true;
                }
                echo str_repeat("  ", $level), '<', $tag;
                if (array_key_exists("{$key} attr", $data)) {
                    #if there's an attribute for this element
                    while (list($attr_name, $attr_value) = each($data["{$key} attr"])) {
                        echo ' ', $attr_name, '="', $attr_value, '"';
                    }
                    reset($data["{$key} attr"]);
                }
                if (is_null($value)) {
                    echo " />\n";
                } elseif (!is_array($value)) {
                    echo '>';
                    if ($is_cdata === true) {
                        echo '<![CDATA[';
                    }
                    echo $value;
                    if ($is_cdata === true) {
                        echo ']]>';
                    }
                    echo "</{$tag}>\n";
                } else {
                    echo ">\n", XML_serialize($value, $encoding, $level + 1), str_repeat("  ", $level), "</{$tag}>\n";
                }
            }
        }
    }
    reset($data);
    if ($level == 0) {
        $str =& ob_get_contents();
        ob_end_clean();
        return $str;
    }
}
开发者ID:4DvAnCeBoY,项目名称:tomatocart-shoppingcart,代码行数:57,代码来源:xml.php

示例3: ob_start

function &XML_serialize(&$data, $level = 0, $prior_key = NULL)
{
    if (!$level) {
        ob_start();
        echo '<?xml version="1.0" ?>', "\n";
    }
    foreach ($data as $key => $value) {
        if (!strpos($key, ' attr')) {
        }
        #if it's not an attribute
        #we don't treat attributes by themselves, so for an empty element
        # that has attributes you still need to set the element to NULL
        if (is_array($value) && array_key_exists(0, $value)) {
            XML_serialize($value, $level, $key);
        } else {
            $tag = $prior_key ? $prior_key : $key;
            echo str_repeat("\t", $level) . '<' . $tag;
            if (array_key_exists("{$key} attr", $data)) {
                foreach ($data[$key . ' attr'] as $attr_name => $attr_value) {
                    echo ' ' . $attr_name . '="' . htmlspecialchars($attr_value) . '"';
                }
                if (is_null($value)) {
                    echo " />\n";
                } else {
                    if (!is_array($value)) {
                        echo '>' . htmlspecialchars($value) . "</{$tag}>\n";
                    } else {
                        echo ">\n" . XML_serialize($value, $level + 1) . str_repeat("\t", $level) . "</{$tag}>\n";
                    }
                }
            }
        }
        if (!$level) {
            $str =& ob_get_contents();
            ob_end_clean();
            return $str;
        }
    }
}
开发者ID:nopticon,项目名称:noptc,代码行数:39,代码来源:xml.php

示例4: serialize

 /**
  *  Serialize output as XML
  *
  *  Example:
  *
  *  <code>
  *  $fp = fopen('feed.xml', 'w')
  *    or die('Could not open feed.xml for writing');
  *  fputs($fp, $rss->serialize());
  *  fclose($fp);
  *  </code>
  *
  *  With specific encoding to allow german umlauts:
  *
  *  <code>
  *  $rss->serialize('ISO-8859-1');
  *  </code>
  *
  *  @param string $charset		Character set to use
  *  @return string			RSS-Feed as XML 
  */
 function serialize($charset = NULL)
 {
     return XML_serialize($this->data, $charset);
 }
开发者ID:eharmon,项目名称:yelly,代码行数:25,代码来源:rss2writer.php

示例5: toXML

 function toXML()
 {
     return XML_serialize($this->_xml, $this->_encoding);
 }
开发者ID:sajad1441,项目名称:TomatoShop-v1,代码行数:4,代码来源:xml.php

示例6: echo_api

 protected function echo_api($code = 1, $res = '')
 {
     header('Content-type: application/json');
     $callback = $this->input->get_post('callback', true);
     //回调函数
     $rt = $this->input->get_post('rt', true);
     //返回类型,支持json/xml
     if (!in_array($rt, array('json', 'xml'))) {
         $rt = 'json';
     }
     $code = intval($code);
     if ($code > 0) {
         $ret['result'] = true;
         $ret['data'] = $res;
     } else {
         $ret['result'] = false;
         $ret['error'] = $res;
     }
     $ret['code'] = $code;
     switch ($rt) {
         case 'xml':
             $this->load->library('xmlparse');
             echo XML_serialize($ret);
             break;
         case 'json':
         default:
             $data = json_encode($ret);
             if (!empty($callback)) {
                 echo $callback . "(" . $data . ")";
             } else {
                 echo $data;
             }
     }
     exit;
 }
开发者ID:Bingle-labake,项目名称:coollive.com.cn,代码行数:35,代码来源:MY_Controller.php

示例7: XMLRPC_error

function XMLRPC_error($faultCode, $faultString, $server = NULL)
{
    $array["methodResponse"]["fault"]["value"]["struct"]["member"] = array();
    $temp =& $array["methodResponse"]["fault"]["value"]["struct"]["member"];
    $temp[0]["name"] = "faultCode";
    $temp[0]["value"]["int"] = $faultCode;
    $temp[1]["name"] = "faultString";
    $temp[1]["value"]["string"] = $faultString;
    $return = XML_serialize($array);
    header("Connection: close");
    header("Content-Length: " . strlen($return));
    header("Content-Type: text/xml");
    header("Date: " . date("r"));
    if ($server) {
        header("Server: {$server}");
    }
    if (defined('XMLRPC_DEBUG') and XMLRPC_DEBUG) {
        XMLRPC_debug('XMLRPC_error', "<p>Sent the following error response:</p>\n\n" . XMLRPC_show($return, 'print_r', true));
    }
    echo $return;
}
开发者ID:KravaDima,项目名称:Lesson_JS_new,代码行数:21,代码来源:xmlrpc.php

示例8: serialize

 function serialize()
 {
     if (!$this->xml) {
         return '';
     }
     return XML_serialize($this->xml, 'theme');
 }
开发者ID:Nerus87,项目名称:PsychoStats,代码行数:7,代码来源:class_themeManager.php

示例9: XML_serialize

function XML_serialize(&$data, $root_key = 'data', $level = 0, $prior_key = NULL)
{
    if ($level == 0) {
        ob_start();
        echo '<?xml version="1.0" ?>', "\n<{$root_key}>\n";
    }
    while (list($key, $value) = each($data)) {
        if (strpos($key, '@') === false) {
            # not an attribute
            # we don't treat attributes by themselves, so for an empty element
            # that has attributes you still need to set the element to NULL
            if (is_array($value) and array_key_exists(0, $value)) {
                XML_serialize($value, $root_key, $level + 1, $key);
            } else {
                $tag = $prior_key ? $prior_key : $key;
                if (is_numeric($tag)) {
                    $tag = "key_{$tag}";
                }
                echo str_repeat("\t", $level + 1), '<', $tag;
                if (array_key_exists("@{$key}", $data)) {
                    # if there's an attribute for this element
                    while (list($attr_name, $attr_value) = each($data["@{$key}"])) {
                        echo ' ', $attr_name, '="', htmlspecialchars($attr_value), '"';
                    }
                    reset($data["@{$key}"]);
                }
                if (is_null($value)) {
                    echo " />\n";
                } elseif (!is_array($value)) {
                    echo '>', htmlspecialchars($value), "</{$tag}>\n";
                } else {
                    echo ">\n", XML_serialize($value, $root_key, $level + 1), str_repeat("\t", $level + 1), "</{$tag}>\n";
                }
            }
        }
    }
    reset($data);
    if ($level == 0) {
        $str = ob_get_contents();
        ob_end_clean();
        return "{$str}</{$root_key}>\n";
    }
}
开发者ID:Nerus87,项目名称:PsychoStats,代码行数:43,代码来源:class_XML.php

示例10: array

$settings['visualization']['style']['button']['text']['font'] = $vis->buttonfont;
$settings['visualization']['style']['button']['text']['size'] = $vis->buttonfontsize;
$settings['visualization']['style']['button']['line'] = array();
$settings['visualization']['style']['button']['line']['size'] = $vis->buttonlinesize;
$settings['visualization']['style']['button']['line']['color'] = $vis->buttonlinecolor;
$settings['visualization']['style']['button']['line']['alpha'] = $vis->buttonlinealpha;
$settings['visualization']['style']['popup'] = array();
$settings['visualization']['style']['popup']['bgcolor'] = $vis->popupbgcolor;
$settings['visualization']['style']['popup']['alpha'] = $vis->popupbgalpha;
$settings['visualization']['style']['popup']['text'] = array();
$settings['visualization']['style']['popup']['text']['font'] = $vis->popupfont;
$settings['visualization']['style']['popup']['text']['size'] = $vis->popupfontsize;
$settings['visualization']['style']['popup']['line'] = array();
$settings['visualization']['style']['popup']['line']['size'] = $vis->popuplinesize;
$settings['visualization']['style']['popup']['line']['color'] = $vis->popuplinecolor;
$settings['visualization']['style']['popup']['line']['alpha'] = $vis->popuplinealpha;
$settings['visualization']['lang'] = array();
$settings['visualization']['lang']['hide'] = get_string('hide', 'gradereport_visual');
$settings['visualization']['lang']['show'] = get_string('show', 'gradereport_visual');
$settings['visualization']['lang']['xlabels'] = get_string('xlabels', 'gradereport_visual');
$settings['visualization']['lang']['ylabels'] = get_string('ylabels', 'gradereport_visual');
$settings['visualization']['lang']['axes'] = get_string('axes', 'gradereport_visual');
$settings['visualization']['lang']['invertaxes'] = get_string('invertaxes', 'gradereport_visual');
/// Turn array into XML string and output.
$xml = XML_serialize($settings);
echo $xml;
/// Clean up cookie if it was created.
if ($cookiewasset) {
    $_COOKIE['MoodleSession' . $_GET['sessioncookie']] = null;
    $_COOKIE['MoodleSessionTest' . $_GET['sessioncookie']] = null;
}
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:31,代码来源:visual_settings.php

示例11: api

 /**
  * Execute an API call
  *
  * In most cases there is no need to call this method directly.  Instead one
  * should use the api1(), api2() or cpanel*() methods (which all call this
  * method, or exec(), internally).
  *
  * @param string $reqtype The type of request used by the cPanel API parser;
  *  valid values are 'exec', 'feature' or 'if'
  * @param int    $version The version of the API; valid values are either
  *  '1' or '2'
  * @param string $module  An API module name
  * @param string $func    An API function name
  * @param mixed  $args    Associate array for API2, ordered array for API1,
  *  string for non exec $reqtypes
  *
  * @see api1()
  * @see api2()
  * @return array Returned response in an array data structure
  * @throws RuntimeException if LiveAPI socket is not available
  */
 public function api($reqtype, $version, $module, $func, $args = array())
 {
     if (!$this->connected) {
         throw new RuntimeException('The LiveAPI PHP socket has closed, unable to continue.');
     }
     $input = array("module" => $module, "reqtype" => $reqtype, "func" => $func, "apiversion" => $version);
     if (count($args)) {
         $input['args'] = $args;
     }
     /**
      *  cPanel engine can process the JSON much much faster than XML
      */
     if (function_exists('json_encode')) {
         $code = "<cpanelaction>\n" . json_encode($input) . "\n</cpanelaction>";
     } else {
         /**
          * This logic flow is provide for BC in the unlikely event that the
          * cPanel engine doesn't not handle JSON.
          * - log this directly to the PHP error log in hopes that it gets
          *   reported
          */
         error_log('cPanel LiveAPI parser returned XML, which is deprecated. ' . 'Please file a bug report at https://tickets.cpanel.net/submit/');
         include_once '/usr/local/cpanel/php/xml.php';
         $temp = array("cpanelaction" => array($input));
         $code = XML_serialize($temp);
     }
     return $this->exec($code);
 }
开发者ID:hoangsoft90,项目名称:cpanel-manager,代码行数:49,代码来源:cpanel.php

示例12: transformXML

 function transformXML($array)
 {
     include_once _SRV_WEBROOT . 'xtFramework/library/phpxml/xml.php';
     return XML_serialize($array);
 }
开发者ID:ZimboBoyd,项目名称:xt_cao,代码行数:5,代码来源:class.xt_cao.php

示例13: while

/**
 * Serialize php arrays to XML.  
 *
 * @param unknown_type $data
 * @param unknown_type $level
 * @param unknown_type $prior_key
 * @return unknown
 */
function &XML_serialize(&$data, $level = 0, $prior_key = NULL)
{ 
    if ($level == 0)
    { 
    	ob_start(); 
    	echo '<?xml version="1.0" ?>',"\n"; 
    } 
    
    while (list($key, $value) = each($data)) 
        if (!strpos($key, ' attr')) 
        {
        	if (is_array($value) and array_key_exists(0, $value))
                XML_serialize($value, $level, $key); 
            else
            { 
                $tag = $prior_key ? $prior_key : $key; 
                echo str_repeat("\t", $level),'<',$tag; 
                if (array_key_exists("$key attr", $data))
                { 
                	while (list($attr_name, $attr_value) = each($data["$key attr"])) 
                        echo ' ',$attr_name,'="',htmlspecialchars($attr_value),'"'; 
                    
                   reset($data["$key attr"]); 
                }

                if (is_null($value)) 
                	echo " />\n"; 
                else if (!is_array($value)) 
                	echo '>',htmlspecialchars($value),"</$tag>\n"; 
                else 
                	echo ">\n",XML_serialize($value, $level+1),str_repeat("\t", $level),"</$tag>\n"; 
            }
    
            reset($data); 
    		if($level == 0)
    		{ 
    			$str = &ob_get_contents(); 
    			ob_end_clean(); 
    			return $str; 
        	} 
        }
}
开发者ID:jawngee,项目名称:Thor,代码行数:50,代码来源:sys.php

示例14: api

 public function api($data, $format = 'json')
 {
     $re_type = $this->CI->input->get('re_type');
     $callback = $this->CI->input->get('callback');
     if (!empty($re_type)) {
         $format = $re_type;
     }
     switch ($format) {
         case 'json':
         case 'jsonp':
             if (is_array($data)) {
                 $data = json_encode($data);
             }
             if (!empty($callback)) {
                 echo $callback . "(" . $data . ")";
             } else {
                 echo $data;
             }
             break;
         case 'xml':
             if (!is_array($data)) {
                 $data = array($data);
             }
             echo XML_serialize($data);
             break;
         default:
             echo json_encode($data);
     }
 }
开发者ID:Bingle-labake,项目名称:coollive.com.cn,代码行数:29,代码来源:fecho_lib.php


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