|
//xml string
$xml_string="<?xml version='1.0'?>
<users>
<user id='398'>
<name>Foo</name>
<email>[email protected]</name>
</user>
<user id='867'>
<name>Foobar</name>
<email>[email protected]</name>
</user>
</users>";
//load the xml string using simplexml
$xml = simplexml_load_string($xml_string);
//loop through the each node of user
foreach ($xml->user as $user)
{
//access attribute
echo $user['id'], ' ';
//subnodes are accessed by -> operator
echo $user->name, ' ';
echo $user->email, '<br />';
}
這里是摘自腳本之家之前發(fā)布的文章。更多的技巧可以參考。
收集的二十一個(gè)實(shí)用便利的php函數(shù)代碼
php技術(shù):PHP XML數(shù)據(jù)解析代碼,轉(zhuǎn)載需保留來(lái)源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。