Haven't seen you for a long time. How are you?
[tr]多日不见了,你好吗?[/tr]
Hello! How are you?
[tr]嘿,你好?[/tr]
Hello, Brooks!How are you?
[tr]喂,布鲁克斯!你好吗?[/tr]
Hi, Barbara, how are you?
[tr]嘿,芭芭拉,你好吗?[/tr]
How are you? -Quite well, thank you.
[tr]你好吗?-很好,谢谢你。[/tr]
经过simplexml_load_string得到:
[U]复制代码[/U] 代码如下:
SimpleXMLElement Object
(
[@attributes] => Array
(
[num] => 219
[id] => 219
[name] => 219
)
[key] => 你好
[pos] => SimpleXMLElement Object
(
)
[acceptation] => Array;Array;Array;
[sent] => Array
(
[0] => SimpleXMLElement Object
(
[orig] => Haven't seen you for a long time. How are you?
[trans] => 多日不见了,你好吗?
)
[1] => SimpleXMLElement Object
(
[orig] => Hello! How are you?
[trans] => 嘿,你好?
)
[2] => SimpleXMLElement Object
(
[orig] => Hello, Brooks!How are you?
[trans] => 喂,布鲁克斯!你好吗?
)
[3] => SimpleXMLElement Object
(
[orig] => Hi, Barbara, how are you?
[trans] => 嘿,芭芭拉,你好吗?
)
[4] => SimpleXMLElement Object
(
[orig] => How are you? -Quite well, thank you.
[trans] => 你好吗?-很好,谢谢你。
)
)
)
我们在PHP语言中可以用以下方法取得我们想要的值:
[U]复制代码[/U] 代码如下:
你好
Array;Array;Array;
Haven't seen you for a long time. How are you?
[tr]多日不见了,你好吗?[/tr]
Hello! How are you?
[tr]嘿,你好?[/tr]
Hello, Brooks!How are you?
[tr]喂,布鲁克斯!你好吗?[/tr]
Hi, Barbara, how are you?
[tr]嘿,芭芭拉,你好吗?[/tr]
How are you? -Quite well, thank you.
[tr]你好吗?-很好,谢谢你。[/tr]
XML;
$xmldata = simplexml_load_string($data);
header("Content-Type: text/html; charset=UTF-8");
print_r($xmldata);
echo "
".trim($xmldata->sent[0]->orig); //Haven't seen you for a long time. How are you?
echo "
".trim($xmldata->key); //你好
?>