Home > php教程 > php手册 > php 数组转xml与xml转换数组实例

php 数组转xml与xml转换数组实例

WBOY
Release: 2016-06-13 09:51:48
Original
953 people have browsed it

本文章来给各位同学介绍两个简单的实例,php 数组转xml与xml转换数组,希望此文章对各位朋友会有所帮助。

php 数组转xml

 代码如下 复制代码

function array2xml($array, $xml = false){
    if($xml === false){
        $xml = new SimpleXMLElement('');
    }
    foreach($array as $key => $value){
        if(is_array($value)){
            array2xml($value, $xml->addChild($key));
        }else{
            $xml->addChild($key, $value);
        }
    }
    return $xml->asXML();
}
 
header('Content-type: text/xml');
print array2xml($array);

php xml转数组

 代码如下 复制代码

$s =

Basic
1
4
3
1
2


EOS;
 
$a = json_decode(json_encode((array) simplexml_load_string($s)),1);
print_r($a);

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template