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


PHP array2xml函数代码示例

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


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

示例1: array2xml

/**
 * @param array $data
 * @param SimpleXMLElement $xml
 * @return SimpleXMLElement
 */
function array2xml(array $data, SimpleXMLElement $xml)
{
    foreach ($data as $k => $v) {
        is_array($v) ? array2xml($v, $xml->addChild($k)) : $xml->addChild($k, $v);
    }
    return $xml;
}
开发者ID:lexeo,项目名称:curl,代码行数:12,代码来源:serverside.php

示例2: order

 /**
  * 下单
  */
 function order($order, $orderdetail)
 {
     $goods = array();
     $good = array();
     foreach ($orderdetail as $product) {
         $good['code'] = $product['sku'];
         $good['name'] = $product['productname'];
         $good['unit'] = '个';
         $good['model'] = $product['sku'];
         $good['brand'] = $product['brand'];
         $good['unitPrice'] = $product['unitprice'];
         $good['sourceArea'] = $product['origin'];
         $good['count'] = $product['num'];
         $good['currencyType'] = 'CNY';
     }
     $goods['@attributes'] = $good;
     $xmlArray = array('@attributes' => array('service' => 'OrderService', 'lang' => 'zh_cn', 'printType' => $this->_system->get('printtype', 'shippment')), 'Head' => "sdafssadfsa", 'Body' => array("Order" => array('@attributes' => array('orderSourceSystem' => '3', 'businessLogo' => $this->_system->get('sendername', 'system'), 'customerOrderNo' => $order['orderno'], 'expressType' => '全球顺', 'payType' => '寄方付', 'recCompany' => $order['consignee'], 'recConcact' => $order['consignee'], 'recTelphone' => $order['consigneetel'], 'recMobile' => $order['consigneetel'], 'recCountry' => '中国', 'recProvinoce' => $order['consigneeprovince'], 'recCityCode' => 'CN', 'recCity' => $order['consigneecity'], 'recCounty' => 'CN', 'recZipcode' => $order['zipcode'], 'recAddress' => $order['consigneeaddress'], 'freight' => $order['feeamount'], 'freightCurrency' => 'CNY'), 'Goods' => $goods)));
     print_r($xmlArray);
     $xml = array2xml($xmlArray, "Request");
     // 生成XML
     //echo $xml;
     $arr = array("verifyCode" => '3DE97718-A922-4B74-97AF-9BD2561DF845', 'Servicefun' => 'issuedOrder', 'server' => 'http://cbtitest.sfb2c.com:8003/CBTA/ws/orderService?wsdl', 'authtoken' => 'CD6A98CF20C3C79D2A7F5C789B5F25C1', 'headerNamespace' => 'http://cbtitest.sfb2c.com:8003/CBTA/');
     $Api = new orderService();
     $response = $Api->getOrderData($xml, $arr);
     return $response;
 }
开发者ID:jin123456bat,项目名称:home,代码行数:29,代码来源:cbti.php

示例3: array2xml

function array2xml($array, $name = 'array', $standalone = TRUE, $beginning = TRUE)
{
    global $nested;
    if ($beginning) {
        if ($standalone) {
            header("content-type:text/xml;charset=utf-8");
        }
        $output .= '<' . '?' . 'xml version="1.0" encoding="UTF-8"' . '?' . '>';
        $output .= '<' . $name . '>';
        $nested = 0;
    }
    // This is required because XML standards do not allow a tag to start with a number or symbol, you can change this value to whatever you like:
    $ArrayNumberPrefix = 'ARRAY_NUMBER_';
    foreach ($array as $root => $child) {
        if (is_array($child)) {
            $output .= str_repeat(" ", 2 * $nested) . '  <' . (is_string($root) ? $root : $ArrayNumberPrefix . $root) . '>';
            $nested++;
            $output .= array2xml($child, NULL, NULL, FALSE);
            $nested--;
            $output .= str_repeat(" ", 2 * $nested) . '  </' . (is_string($root) ? $root : $ArrayNumberPrefix . $root) . '>';
        } else {
            $output .= str_repeat(" ", 2 * $nested) . '  <' . (is_string($root) ? $root : $ArrayNumberPrefix . $root) . '><![CDATA[' . $child . ']]></' . (is_string($root) ? $root : $ArrayNumberPrefix . $root) . '>';
        }
    }
    if ($beginning) {
        $output .= '</' . $name . '>';
    }
    return $output;
}
开发者ID:votainteligente,项目名称:legislativo,代码行数:29,代码来源:array2xml.php

示例4: array2xml

/**
 * Convert array to XML format
 *
 * @param $arr    array with data
 * @param $tag    main tag <main tag>XML data</main tag>
 * @return XML presentation of data
 */
function array2xml($arr, $tag = false)
{
    $res = '';
    foreach ($arr as $k => $v) {
        if (is_array($v)) {
            if (!is_numeric($k) && trim($k)) {
                $res .= count($v) ? '<' . $k . '>' . array2xml($v) . '</' . $k . '>' : '<' . $k . '/>';
            } elseif ($tag) {
                $res .= '<' . $tag . '>' . array2xml($v) . '</' . $tag . '>';
            } else {
                $res .= array2xml($v);
            }
        } else {
            if (!is_numeric($k) && trim($k)) {
                $res .= strlen(trim($v)) ? '<' . $k . '>' . $v . '</' . $k . '>' : '<' . $k . '/>';
            } elseif ($tag) {
                $res .= '<' . $tag . '>' . $v . '</' . $tag . '>';
            } else {
                echo 'Error: array without tag';
                exit;
            }
        }
    }
    return $res;
}
开发者ID:Prashank25,项目名称:dolphin.pro,代码行数:32,代码来源:util.inc.php

示例5: outputvariables

 function outputvariables()
 {
     global $_G;
     $variables = array();
     foreach ($this->params as $param) {
         if (substr($param, 0, 1) == '$') {
             if ($param == '$_G') {
                 continue;
             }
             $var = substr($param, 1);
             if (preg_match("/^[a-zA-Z_][a-zA-Z0-9_]*\$/", $var)) {
                 $variables[$param] = $GLOBALS[$var];
             }
         } else {
             if (preg_replace($this->safevariables, '', $param) !== $param) {
                 continue;
             }
             $variables[$param] = getglobal($param);
         }
     }
     $xml = array('Version' => $this->version, 'Charset' => strtoupper($_G['charset']), 'Variables' => $variables);
     if (!empty($_G['messageparam'])) {
         $xml['Message'] = $_G['messageparam'];
     }
     require_once libfile('class/xml');
     echo array2xml($xml);
     exit;
 }
开发者ID:dalinhuang,项目名称:hlwbbsvincent,代码行数:28,代码来源:class_mobiledata.php

示例6: array2xml

function array2xml($data, $rootNodeName = 'data', $xml = null)
{
    // turn off compatibility mode as simple xml throws a wobbly if you don't.
    if (ini_get('zend.ze1_compatibility_mode') == 1) {
        ini_set('zend.ze1_compatibility_mode', 0);
    }
    if ($xml == null) {
        /** @var \SimpleXMLElement $xml */
        $xml = simplexml_load_string("<?xml version='1.0' encoding='utf-8'?><{$rootNodeName} />");
    }
    // loop through the data passed in.
    foreach ($data as $key => $value) {
        // no numeric keys in our xml please!
        if (is_numeric($key)) {
            // make string key...
            $key = "unknownNode_" . (string) $key;
        }
        // replace anything not alpha numeric
        $key = preg_replace('/[^a-z]/i', '', $key);
        // if there is another array found recrusively call this function
        if (is_array($value)) {
            $node = $xml->addChild($key);
            // recrusive call.
            array2xml($value, $rootNodeName, $node);
        } else {
            // add single node.
            $value = htmlentities($value);
            $xml->addChild($key, $value);
        }
    }
    // pass back as string. or simple xml object if you want!
    return $xml->asXML();
}
开发者ID:xialeistudio,项目名称:thinkphp-inaction,代码行数:33,代码来源:function.php

示例7: send

/**
 * 将数组转换为xml,发送消息到微信
 *
 * @params array $data 发送消息结构数组
 */
function send($data = '')
{
    if (!empty($data)) {
        $xml = array2xml($data, 'xml');
    } else {
        $xml = '';
    }
    echo $xml;
}
开发者ID:jurimengs,项目名称:bangsm,代码行数:14,代码来源:index-guodapeng.php

示例8: api

function api($core, $app, $func, $type, $id)
{
    $apps = array('wm' => array('flows', 'offers', 'pub', 'land', 'sites', 'stats', 'lead', 'sources', 'add', 'edit', 'del'), 'sale' => array('list', 'view', 'edit'));
    $na = array('wm-pub', 'wm-land');
    $app = $core->text->link($app);
    $func = $core->text->link($func);
    $type = $core->text->link($type);
    if ($id) {
        $ids = explode('-', $id, 2);
        $id = (int) $ids[0];
        $key = $core->text->link($ids[1]);
    } else {
        $id = $key = false;
    }
    if (in_array($func, $apps[$app])) {
        if ($id) {
            $uk = $core->user->get($id, 'user_api');
            if ($uk != $key) {
                $ck = hash_hmac('sha1', http_build_query($core->post), $uk);
                $auth = $ck == $key ? 1 : 0;
            } else {
                $auth = 1;
            }
        } else {
            $auth = in_array("{$app}-{$func}", $na) ? 1 : 0;
        }
        if ($auth) {
            $fname = 'api_' . $app . '_' . $func;
            if (function_exists($fname)) {
                $result = $fname($core, $id);
            } else {
                $result = array('status' => 'error', 'error' => 'func');
            }
        } else {
            $result = array('status' => 'error', 'error' => 'key');
        }
    } else {
        $result = array('status' => 'error', 'error' => 'app');
    }
    switch ($type) {
        case 'text':
            echo http_build_query($result);
            break;
        case 'raw':
            echo $result;
            break;
        case 'xml':
            echo array2xml($result, $func);
            break;
        case 'json':
            echo defined('JSON_UNESCAPED_UNICODE') ? json_encode($result, JSON_UNESCAPED_UNICODE) : json_encode($result);
            break;
        default:
            echo serialize($result);
    }
}
开发者ID:Burick,项目名称:altercpa,代码行数:56,代码来源:api.php

示例9: cl_camara_division2xml_xml

function cl_camara_division2xml_xml($division_id, $original_html = false)
{
    $out = array();
    $division = cl_camara_division2array($division_id);
    $out = $division;
    if (!$original_html) {
        unset($out['original_html']);
    }
    $xml = array2xml($out, 'votainteligente.cl', true);
    return $xml;
}
开发者ID:votainteligente,项目名称:legislativo,代码行数:11,代码来源:cl_camara_getDivision.php

示例10: render

 public function render($buffer = false)
 {
     // Build Element Structure
     $this->build_element_structure($this->table_elements['header'], $this->table_data['elements']['header']);
     $this->build_element_structure($this->table_elements['body'], $this->table_data['elements']['body']);
     $this->build_element_structure($this->table_elements['footer'], $this->table_data['elements']['footer']);
     // Convert Table Data to XML
     $this->inset_val = array2xml('table_data', $this->table_data);
     // Render Table Element
     parent::render($buffer);
 }
开发者ID:codifyllc,项目名称:phpopenfw,代码行数:11,代码来源:table.class.php

示例11: array2xml

/**
 * 数组转为xML
 * @param $var 数组
 * @param $type xml的根节点
 * @param $tag
 * 返回xml格式
 */
function array2xml($var, $type = 'root', $tag = '')
{
    $ret = '';
    if (!is_int($type)) {
        if ($tag) {
            return array2xml(array($tag => $var), 0, $type);
        } else {
            $tag .= $type;
            $type = 0;
        }
    }
    $level = $type;
    $indent = str_repeat("\t", $level);
    if (!is_array($var)) {
        $ret .= $indent . '<' . $tag;
        $var = strval($var);
        if ($var == '') {
            $ret .= ' />';
        } else {
            if (!preg_match('/[^0-9a-zA-Z@\\._:\\/-]/', $var)) {
                $ret .= '>' . $var . '</' . $tag . '>';
            } else {
                $ret .= "><![CDATA[{$var}]]></{$tag}>";
            }
        }
        $ret .= "\n";
    } else {
        if (!(is_array($var) && count($var) && array_keys($var) !== range(0, sizeof($var) - 1)) && !empty($var)) {
            foreach ($var as $tmp) {
                $ret .= array2xml($tmp, $level, $tag);
            }
        } else {
            $ret .= $indent . '<' . $tag;
            if ($level == 0) {
                $ret .= '';
            }
            if (isset($var['@attributes'])) {
                foreach ($var['@attributes'] as $k => $v) {
                    if (!is_array($v)) {
                        $ret .= sprintf(' %s="%s"', $k, $v);
                    }
                }
                unset($var['@attributes']);
            }
            $ret .= ">\n";
            foreach ($var as $key => $val) {
                $ret .= array2xml($val, $level + 1, $key);
            }
            $ret .= "{$indent}</{$tag}>\n";
        }
    }
    return $ret;
}
开发者ID:jin123456bat,项目名称:home,代码行数:60,代码来源:function.php

示例12: array2xml

function array2xml($arr, $htmlon = TRUE, $isnormal = FALSE, $level = 1) {
	$s = $level == 1 ? "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n<root>\r\n" : '';
	$space = str_repeat("\t", $level);
	foreach($arr as $k => $v) {
		if(!is_array($v)) {
			$s .= $space."<item id=\"$k\">".($htmlon ? '<![CDATA[' : '').$v.($htmlon ? ']]>' : '')."</item>\r\n";
		} else {
			$s .= $space."<item id=\"$k\">\r\n".array2xml($v, $htmlon, $isnormal, $level + 1).$space."</item>\r\n";
		}
	}
	$s = preg_replace("/([\x01-\x08\x0b-\x0c\x0e-\x1f])+/", ' ', $s);
	return $level == 1 ? $s."</root>" : $s;
}
开发者ID:xDiglett,项目名称:discuzx30,代码行数:13,代码来源:class_xml.php

示例13: array2xml

function array2xml($arr, $htmlon = TRUE, $isnormal = FALSE, $level = 1, $encodeing = 'ISO-8859-1')
{
    $s = $level == 1 ? "<?xml version=\"1.0\" encoding=\"" . $encodeing . "\"?>\r\n<root>\r\n" : '';
    $space = str_repeat("\t", $level);
    foreach ($arr as $k => $v) {
        if (!is_array($v)) {
            $s .= $space . "<item id=\"{$k}\">" . ($htmlon ? '<![CDATA[' : '') . $v . ($htmlon ? ']]>' : '') . "</item>\r\n";
        } else {
            $s .= $space . "<item id=\"{$k}\">\r\n" . array2xml($v, $htmlon, $isnormal, $level + 1, $encodeing) . $space . "</item>\r\n";
        }
    }
    $s = preg_replace("/([-\v-\f-])+/", ' ', $s);
    return $level == 1 ? $s . "</root>" : $s;
}
开发者ID:druphliu,项目名称:dzzoffice,代码行数:14,代码来源:class_xml.php

示例14: packageData

 /**
  *  同步返回的消息
  */
 public function packageData($postData, $paramsData)
 {
     //LogUtil::logs(" index.php send_msg =====> ".$postData, getLogFile('/business.log'));
     $data = array();
     if (!empty($paramsData)) {
         $commData['ToUserName'] = $postData['FromUserName'];
         $commData['FromUserName'] = $postData['ToUserName'];
         $commData['CreateTime'] = time();
         $data = array_merge($commData, $paramsData);
     }
     //LogUtil::logs(" index.php send_msg =====> ".$data, getLogFile('/business.log'));
     if (!empty($data)) {
         $xml = array2xml($data, 'xml');
     } else {
         $xml = '';
     }
     return $xml;
 }
开发者ID:jurimengs,项目名称:bangsm,代码行数:21,代码来源:TypeParent.php

示例15: array2xml

function array2xml($data, $root = 'data', $xml = null)
{
    if ($xml == null) {
        $xml = simplexml_load_string("<?xml version='1.0' encoding='utf-8'?><{$root}/>");
    }
    foreach ($data as $key => $value) {
        if (is_array($value)) {
            if (is_int($key)) {
                $key = 'item';
            }
            $node = $xml->addChild($key);
            array2xml($value, $root, $node);
        } else {
            $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
            $xml->addChild($key, $value);
        }
    }
    return $xml->asXML();
}
开发者ID:noikiy,项目名称:kohana,代码行数:19,代码来源:Function.php


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