[转] – php5将xml转换成json最简单的办法

原文地址:http://heatspace.cn/?p=205

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$xml = <books>
truetrue<book id="1">
truetruetrue<title>Code Generation in Action</title>
truetruetrue<author><first>Jack</first><last>Herrington</last></author>
truetruetrue<publisher>Manning</publisher>
truetrue</book>
truetrue<book id="2">
truetruetrue<title>PHP Hacks</title>
truetruetrue<author><first>Jack</first><last>Herrington</last></author>
truetruetrue<publisher>O‘Reilly</publisher>
truetrue</book>
truetrue<book id="3">
truetruetrue<title>Podcasting Hacks</title>
truetruetrue<author><first>Jack</first><last>Herrington</last></author>
truetruetrue<publisher>O’Reilly</publisher>
truetrue</book>
true</books>
1
echo $json = json_encode (simplexml_load_string($xml));