[請益] check simpleXML object的屬性
小弟新手,請板上先進多指教
小弟的code需要檢查xml裡是否有某一個標籤
XML範例如下
<client>
<id>1171</id>
<address>1.1.1.1</address>
<time>149318</time>
<flashver>LNX9,0,124,2</flashver>
<dropped>931</dropped>
<avsync>-210965</avsync>
<timestamp>210965</timestamp>
<active/>
</client>
<client>
<id>1164</id>
<address>1.1.1.1</address>
<time>173845</time>
<dropped>0</dropped>
<avsync>-211103</avsync>
<timestamp>211103</timestamp>
<publishing/> <------要檢查的標籤
<active/>
</client>
需要進行的檢查是,
看client裡面有沒有<publishing/>這個標籤
我目前的寫法是
先把XML parse成sinpleXML Object
然後跑以下的程式碼檢查
foreach ($clients as $client) {
if(isset($client->publishing))
{
echo "We got publishing <br />";
}
}
結果連沒有<publishing/>的client也會echo出東西來....
想請問這個例子裡我該怎麼做比較好?
謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.25.231.45
※ 文章網址: http://www.ptt.cc/bbs/PHP/M.1416974260.A.042.html
※ 編輯: youneverknow (114.25.231.45), 11/26/2014 11:59:30
→
11/26 12:07, , 1F
11/26 12:07, 1F
感謝,解開了
※ 編輯: youneverknow (114.25.231.45), 11/26/2014 15:41:09
推
11/26 17:48, , 2F
11/26 17:48, 2F
PHP 近期熱門文章
PTT數位生活區 即時熱門文章