facebook twitter hatena line google mixi email

Php/xml/SimpleXMLElement

提供: 初心者エンジニアの簡易メモ
移動: 案内検索

配列からxml生成

$xmlstr = "<?xml version='1.0' encoding='utf-8'?><tags></tags>";
$xml = new SimpleXMLElement($xmlstr);
$tags = [
   'name' => 'taro',
   'age' => 1
];
foreach($tags as $key => $value) {
   $xml->addChild($key, $value);
}
echo $xml->asXML();

xmlから配列へ

$xml = simplexml_load_string($resxml);
$json = json_encode($xml);
$array = json_decode($json, TRUE);
print_r($array);