「Php/xml/SimpleXMLElement」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→xmlから配列へ) |
|||
| 行16: | 行16: | ||
$array = json_decode($json, TRUE); | $array = json_decode($json, TRUE); | ||
print_r($array); | print_r($array); | ||
| + | |||
| + | ==utf-8をエスケープしないように== | ||
| + | echo json_encode($kanaMappings, JSON_UNESCAPED_UNICODE); | ||
2023年5月9日 (火) 23:10時点における最新版
配列から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);
utf-8をエスケープしないように
echo json_encode($kanaMappings, JSON_UNESCAPED_UNICODE);
