后端开发|php教程
nbsp,gt,lt,context,password
后端开发-php教程
多维PHP数组如何转换成xml格式的数据?
PHP数组是这样的:
求购金融源码,ubuntu本地更新php,java爬虫检测页面,php接收img,seo建站盈利lzw
array(4)
{
["auth"]=> array(3)
{
["user"]=> string(8) "customer"
["password"]=> string(8) "password"
["context"]=> string(1) "4"
}
["owner"]=> array(2)
{
["user"]=> string(9) "customer2"
["context"]=> string(1) "4"
}
["language"]=> string(2) "en"
["task"]=> array(1)
{
["code"]=> string(4) "0130"
}
}
转换成xml格式后的数据格式是这样的:
一键分享最新挂机赚钱app源码,查看ubuntu硬盘信息,国内的爬虫市场,向军php和韩顺平php,外贸seo内容lzw
customer
password
4
customer2
4
en
0130
php数组 xml
稀有端游源码,ubuntu安装软件pl,为什么禁止爬虫,php Y,seo专员经理lzw
分享到: ?array(3)?{[“user”]=>?string(8)?”customer”?[“passw…’ data-pics=”>
——解决方案——————–
$ar=array
(
"auth"=> array
(
"user"=> "customer" ,
"password"=> "password" ,
"context"=> "4"
) ,
"owner"=> array
(
"user"=> "customer2" ,
"context"=> "4"
) ,
"language"=> "en" ,
"task"=> array
(
"code"=> "0130"
)
);
$doc = new DOMDocument(1.0,UTF-8);
// we want a nice output
$doc->formatOutput = true;
$root = $doc->createElement( equest);
$root = $doc->appendChild($root);
foreach($ar as $title=>$title_v){
$title = $doc->createElement($title);
$title = $root->appendChild($title);
if(is_array($title_v)){
foreach($title_v as $k=>$v){
$k = $doc->createElement($k);
$k = $title->appendChild($k);
$text = $doc->createTextNode($v);
$text = $k->appendChild($text);
}
}else{
$text = $doc->createTextNode($title_v);
$text = $title->appendChild($text);
}
}
echo $doc->saveXML();
——解决方案——————–
$ar = array(
"auth" => array(
"user" => "customer",
"password" => "password",
"context" => "4",
),
"owner" => array(
"user" => "customer2",
"context" => "4",
),
"language" => "en",
"task" => array(
"code" => "0130",
),
);
$xml = simplexml_load_string(\);
create($ar, $xml);
echo $xml->saveXML();
function create($ar, $xml) {
foreach($ar as $k=>$v) {
if(is_array($v)) {
$x = $xml->addChild($k);
create($v, $x);
}else $xml->addChild($k, $v);
}
}
customer
password
4
customer2
4
en
0130