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


PHP array_to_xml函数代码示例

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


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

示例1: array_to_xml

function array_to_xml($phpResponse, &$phpResponseToXML)
{
    foreach ($phpResponse as $key => $value) {
        if (is_array($value)) {
            if (!is_numeric($key)) {
                // For non-numeric keys, give name same as key to the node
                $subnode = $phpResponseToXML->addChild("{$key}");
                // Recursive call to the function since the value was an array
                array_to_xml($value, $subnode);
            } else {
                // For numeric keys, give a name to the node
                //$subnode = $phpResponseToXML->addChild("item$key");
                if (current($phpResponseToXML->xpath('parent::*'))) {
                    $subnode = $phpResponseToXML->addChild("Showing");
                } else {
                    $subnode = $phpResponseToXML->addChild("Show");
                }
                //Recursive call to the function since the value was an array
                array_to_xml($value, $subnode);
            }
        } else {
            // Save the node and its value in XMLFiles format
            //$phpResponseToXML->addChild("$key","$value");
            $phpResponseToXML->{$key} = $value;
        }
    }
}
开发者ID:CheukYuen,项目名称:Ticketing_System_Cinequest,代码行数:27,代码来源:generateXML_EventsWithShowings.php

示例2: array_to_xml

/**
* 数组转XML
*/
function array_to_xml($arr)
{
    $xml = '';
    if (!empty($arr)) {
        foreach ($arr as $key => $value) {
            if (is_array($value)) {
                if (array_key_exists(0, $value)) {
                    foreach ($value as $kk => $vv) {
                        $xml .= '<' . $key . ' id="' . $key . '_' . $kk . '">' . "\n";
                        $xml .= array_to_xml($vv);
                        $xml .= '</' . $key . '>' . "\n";
                    }
                } else {
                    if (!is_numeric($key)) {
                        $xml .= '<' . $key . '>' . "\n";
                    }
                    $xml .= array_to_xml($value);
                    if (!is_numeric($key)) {
                        $xml .= '</' . $key . '>' . "\n";
                    }
                }
            } else {
                $xml .= '<' . $key . '>' . $value . '</' . $key . '>' . "\n";
            }
        }
    }
    return $xml;
}
开发者ID:ToogleLiu,项目名称:code,代码行数:31,代码来源:array_to_xml.php

示例3: array_to_xml

 private function array_to_xml($array, $container = 'response', $is_root = true)
 {
     if (!is_array($array)) {
         return array_to_xml(array($array));
     }
     $xml = '';
     if ($is_root) {
         $xml .= '<?xml version="1.0" encoding="utf-8"?>';
         $xml .= "<{$container}>";
     }
     foreach ($array as $key => $value) {
         // make sure key is a string
         $elem = $key;
         if (!is_string($key) && !empty($container)) {
             $elem = $container;
         }
         $xml .= "<{$elem}>";
         if (is_array($value)) {
             if (array_keys($value) !== array_keys(array_keys($value))) {
                 $xml .= array_to_xml($value, '', false);
             } else {
                 $xml .= array_to_xml($value, r('/s$/', '', $elem), false);
             }
         } else {
             $xml .= htmlspecialchars($value, ENT_COMPAT, 'ISO-8859-1') != $value ? "<![CDATA[{$value}]]>" : $value;
         }
         $xml .= "</{$elem}>";
     }
     if ($is_root) {
         $xml .= "</{$container}>";
     }
     return preg_replace('/[\\x00-\\x1F\\x7F]/', '', $xml);
 }
开发者ID:ranzhe,项目名称:tinytinyrss-fever-plugin,代码行数:33,代码来源:fever_api.php

示例4: as_nprml

/**
 * as_nprml(): Translates a post to NPRML.  Returns an XML string.
 */
function as_nprml($post)
{
    $story = post_to_nprml_story($post);
    $doc = array();
    $doc[] = array('tag' => 'list', 'children' => array(array('tag' => 'story', 'children' => $story)));
    $ret_xml = array_to_xml('nprml', array('version' => '0.93'), $doc);
    return $ret_xml;
}
开发者ID:mike-douglas,项目名称:WP-DS-NPR-API,代码行数:11,代码来源:nprml.php

示例5: smarty_function_xml

function smarty_function_xml($params, &$smarty)
{
    // initializing or creating array
    $player_info = $params[toXml];
    // creating object of SimpleXMLElement
    $xml_player_info = new SimpleXMLElement("<?xml version=\"1.0\"?><player_info></player_info>");
    // function call to convert array to xml
    array_to_xml($player_info, $xml_player_info);
    //print
    return $xml_player_info->asXML();
}
开发者ID:Alambos,项目名称:fullserver,代码行数:11,代码来源:function.xml.php

示例6: wsResponse

function wsResponse($format, $status, $return)
{
    $response = array("status" => $status, "response" => $return);
    if (strtolower($format) == 'json') {
        print json_encode($response);
    } else {
        if (strtolower($format) == 'xml') {
            print array_to_xml($response, new SimpleXMLElement('<root />'))->asXML();
        }
    }
}
开发者ID:JhunCabas,项目名称:avarice-nms,代码行数:11,代码来源:index.php

示例7: array_to_xml

 function array_to_xml($data, &$xml_data)
 {
     foreach ($data as $key => $value) {
         if (is_array($value)) {
             if (is_numeric($key)) {
                 $key = 'item' . $key;
             }
             $subnode = $xml_data->addChild($key);
             array_to_xml($value, $subnode);
         } else {
             $xml_data->addChild("item", htmlspecialchars("{$value}"));
         }
     }
 }
开发者ID:matty-digital,项目名称:mattbowytz,代码行数:14,代码来源:simple_api.php

示例8: get_comments_xml

function get_comments_xml($filename, $cons)
{
    global $wpdb;
    $sql = "SELECT post_title,comment_ID,comment_author, comment_date_gmt, comment_content\n\t\t\tFROM {$wpdb->comments}\n\t\t\t\tLEFT OUTER JOIN {$wpdb->posts} ON ({$wpdb->comments}.comment_post_ID = {$wpdb->posts}.ID)\n\t\t\t\tINNER JOIN {$wpdb->term_relationships} as r1 ON ({$wpdb->posts}.ID = r1.object_id)\n\t\t\t\tINNER JOIN {$wpdb->term_taxonomy} as t1 ON (r1.term_taxonomy_id = t1.term_taxonomy_id)\n\t\t\tWHERE comment_approved = '1'\n\t\t\t\tAND comment_type = ''\n\t\t\t\tAND post_password = ''\n\t\t\t\tAND t1.taxonomy = 'category'\n\t\t\t\tAND t1.term_id = " . $cons . "\n\t\t\torder by comment_date_gmt";
    $data = $wpdb->get_results($sql, ARRAY_A);
    // creating object of SimpleXMLElement
    $xml_data = new SimpleXMLElement('<?xml version="1.0"?><data></data>');
    // function call to convert array to xml
    array_to_xml($data, $xml_data);
    //saving generated xml file;
    $result = $xml_data->asXML();
    echo $result;
    exit;
}
开发者ID:PDM-OpenGov,项目名称:opengov_consultations,代码行数:14,代码来源:exporter.php

示例9: array_to_xml

function array_to_xml(array $arr, SimpleXMLElement $xml)
{
    try {
        foreach ($arr as $k => $v) {
            $kk = $k;
            if (is_numeric($k)) {
                $kk = 'i-' . $k;
            }
            is_array($v) ? array_to_xml($v, $xml->addChild($kk)) : $xml->addChild($kk, str_replace('&', '&amp;', $v));
        }
    } catch (Exception $e) {
    }
    return $xml;
}
开发者ID:malimu,项目名称:CrisisTracker,代码行数:14,代码来源:common_functions.php

示例10: export_small

 public function export_small($array, $level = 1)
 {
     $xml = '';
     foreach ($array as $key => $value) {
         $key = strtolower($key);
         if (is_object($value)) {
             $value = get_object_vars($value);
         }
         // convert object to array
         if (is_array($value)) {
             $multi_tags = false;
             foreach ($value as $key2 => $value2) {
                 if (is_object($value2)) {
                     $value2 = get_object_vars($value2);
                 }
                 // convert object to array
                 if (is_array($value2)) {
                     $xml .= str_repeat("\t", $level) . "<{$key}>\n";
                     $xml .= array_to_xml($value2, $level + 1);
                     $xml .= str_repeat("\t", $level) . "</{$key}>\n";
                     $multi_tags = true;
                 } else {
                     if (trim($value2) != '') {
                         if (htmlspecialchars($value2) != $value2) {
                             $xml .= str_repeat("\t", $level) . "<{$key2}><![CDATA[{$value2}]]>" . "</{$key2}>\n";
                         } else {
                             $xml .= str_repeat("\t", $level) . "<{$key2}>{$value2}</{$key2}>\n";
                             // changed $key to $key2
                         }
                     }
                     $multi_tags = true;
                 }
             }
             if (!$multi_tags and count($value) > 0) {
                 $xml .= str_repeat("\t", $level) . "<{$key}>\n";
                 $xml .= array_to_xml($value, $level + 1);
                 $xml .= str_repeat("\t", $level) . "</{$key}>\n";
             }
         } else {
             if (trim($value) != '') {
                 if (htmlspecialchars($value) != $value) {
                     $xml .= str_repeat("\t", $level) . "<{$key}>" . "<![CDATA[{$value}]]></{$key}>\n";
                 } else {
                     $xml .= str_repeat("\t", $level) . "<{$key}>{$value}</{$key}>\n";
                 }
             }
         }
     }
     return $xml;
 }
开发者ID:hscomp2002,项目名称:superp,代码行数:50,代码来源:xml_class.php

示例11: array_to_xml

function array_to_xml($data, &$xml_data)
{
    foreach ($data as $key => $value) {
        if (is_array($value)) {
            if (is_numeric($key)) {
                $key = 'LineItem';
                //dealing with <0/>..<n/> issues
            }
            $subnode = $xml_data->addChild($key);
            array_to_xml($value, $subnode);
        } else {
            $xml_data->addChild("{$key}", htmlspecialchars("{$value}"));
        }
    }
}
开发者ID:harishannam,项目名称:chargebee-xero-test,代码行数:15,代码来源:json.php

示例12: array_to_xml

function array_to_xml($arr_in, &$xml_out)
{
    foreach ($arr_in as $key => $value) {
        if (is_array($value)) {
            if (!is_numeric($key)) {
                $subnode = $xml_out->addChild("{$key}");
                array_to_xml($value, $subnode);
            } else {
                array_to_xml($value, $xml_out);
            }
        } else {
            $xml_out->addChild("{$key}", "{$value}");
        }
    }
}
开发者ID:shalintripathi,项目名称:WHMCS-Modules,代码行数:15,代码来源:timetracker.php

示例13: arrayToXML

    public function arrayToXML($request) {
        $xml_data = new \SimpleXMLElement('<Request></Request>');

        foreach ($request as $key => $value) {
            if (is_array($value)) {
                if (is_numeric($key)) {
                    $key = 'item' . $key;
                }
                $subnode = $xml_data->addChild($key);
                array_to_xml($value, $subnode);
            } else {
                $xml_data->addChild("$key", htmlspecialchars("$value"));
            }
        }
        return $xml_data;
    }
开发者ID:valdy89,项目名称:diplomaThesis,代码行数:16,代码来源:MapleAPI.php

示例14: my_xmlapi_output

function my_xmlapi_output($array, $print = true)
{
    if (isset($array['success']) && is_bool($array['success'])) {
        $array['success'] = $array['success'] == true ? 1 : 0;
    }
    // creating object of SimpleXMLElement
    $xml = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"UTF-8\"?><root></root>");
    // function call to convert array to xml
    array_to_xml($array, $xml);
    if ($print) {
        header('Content-Type: text/xml');
        print $xml->asXML();
        die;
    }
    return $xml->asXML();
}
开发者ID:binaryelites,项目名称:tstxmlclient,代码行数:16,代码来源:config.php

示例15: array_to_xml

function array_to_xml($student_info, &$xml_student_info)
{
    foreach ($student_info as $key => $value) {
        if (is_array($value)) {
            if (!is_numeric($key)) {
                $subnode = $xml_student_info->addChild("{$key}");
                array_to_xml($value, $subnode);
            } else {
                $subnode = $xml_student_info->addChild("item{$key}");
                array_to_xml($value, $subnode);
            }
        } else {
            $xml_student_info->addChild("{$key}", htmlspecialchars("{$value}"));
        }
    }
}
开发者ID:CamTosh,项目名称:php-rest-wrapper,代码行数:16,代码来源:xml-converter.php


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