U可以使用PHP的simple_xml功能将XML文件加载到一个类。
http://php.net/manual/de/book.simplexml.php
编辑用一个例子:
// XML example
$xmlContent = '<server name="GuiltyofDestruction" phonetic="God" comment="http://guiltyofdestruction.com" auth="1" maxclients="25" uptime="137600" platform="Linux-i386" version="3.0.6" channelcount="36" clientcount="1" voicecodec="GSM 6.10" voiceformat="44 KHz, 16 bit"><channel cid="0" pid="-1" prot="0" name="Lobby" comm="">
<channel cid="1033" pid="0" prot="1" name="Admin" comm=""/>
<channel cid="1030" pid="0" prot="0" name="AFK Channel" comm="AFK">
<client admin="1" cid="1030" phan="0" ping="182" sec="67575" name="US_ChairForce" comm=""/>
</channel>
</channel>
</server>';
// Loading XML information as object
//$xml = simplexml_load_file('http://ventrilostatus.net/xml/V98.DARKSTARLLC.COM:3789/'); // for files
$xml = simplexml_load_string($xmlContent); // for strings
foreach($xml->channel->channel as $channel) {
if($channel->client)
echo $channel->client->attributes()->name; // returns "US_ChairForce"
}
我觉得现在很清楚。您必须遍历每个渠道并寻找客户。
来源
2014-10-03 16:48:45
Tyr
您可以使用XML-PHP库将有效的XML代码转换为php对象或数组。 – 2014-10-03 16:48:40