XML链接到PHP数组
我无法将此页面()数组放入php。我对xml不是很在行,目前只能让它显示: 服务器 频道 频道 频道 (等) 有人能帮我把频道名称和用户显示出来吗? 如果在查看时没有客户端,则会是:XML链接到PHP数组,php,arrays,xml,Php,Arrays,Xml,我无法将此页面()数组放入php。我对xml不是很在行,目前只能让它显示: 服务器 频道 频道 频道 (等) 有人能帮我把频道名称和用户显示出来吗? 如果在查看时没有客户端,则会是: <client admin="1" cid="994" phan="0" ping="186" sec="56935" name="WHERE USER'S NAME HIS HERE" comm=""/> U可以使用PHP的简单xml函数将xml文件加载到类中 用一个例子编辑: // XML ex
<client admin="1" cid="994" phan="0" ping="186" sec="56935" name="WHERE USER'S NAME HIS HERE" comm=""/>
U可以使用PHP的简单xml函数将xml文件加载到类中 用一个例子编辑:
// 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"
}
//XML示例
$xmlContent='1〕
';
//将XML信息作为对象加载
//$xml=simplexml\u加载\u文件('http://ventrilostatus.net/xml/V98.DARKSTARLLC.COM:3789/'); // 档案
$xml=simplexml_load_字符串($xmlContent);//弦乐
foreach($xml->channel->channel as$channel){
如果($channel->client)
echo$channel->client->attributes()->name;//返回“US_ChairForce”
}
我想现在清楚了。您必须遍历每个频道并查找客户端。抱歉,这是我更新的代码:
<?PHP
echo "<table width=\"209\" bgcolor=\"#0d0d0d\">";
$xml = simplexml_load_file('http://ventrilostatus.net/xml/V98.DARKSTARLLC.COM:3789/'); // for files
//$xml = simplexml_load_string($xmlContent); // for strings
foreach($xml->channel as $lobby) {
echo "<tr><td>";
echo "<img src='http://view.light-speed.com//images/s_vent2/server_icon.gif' />";
echo "<font color=\"#FFFFFF\">";
echo $lobby->attributes()->name;
echo "</font>";
echo "</td></tr>";
}
foreach($xml->channel->channel as $channel) {
if($channel->attributes()->prot == "0"){
echo "<tr><td> ";
echo "<img src='http://view.light-speed.com//images/s_vent2/channel_0_empty.gif' />";
echo "<font color=\"#ffffff\">";
echo $channel->attributes()->name;
echo "</font>";
echo "</td></tr>";
}else{
echo "<tr><td> ";
echo "<img src='http://view.light-speed.com//images/s_vent2/channel_1_empty.gif' />";
echo "<font color=\"#ffffff\">";
echo $channel->attributes()->name;
echo "</font>";
echo "</td></tr>";
}
if($channel->client){
for ( $i = 0; $i < count($channel->client); $i++ ){
$client = $channel->client[ $i ];
if ( $client->attributes()->cid != $client->attributes()->cid )
continue;
echo "<tr><td> ";
echo "<img src='http://view.light-speed.com//images/s_vent2/player.gif' /><font color=\"#009e1a\">";
if($client->attributes()->admin == "1"){
echo $client->attributes()->name;
echo " <font color=\"#ff0000\">(Admin)</font>";
}else{
echo $client->attributes()->name;
}
echo "</td></tr>";
}
}
foreach($channel->channel as $subchannel) {
if($subchannel->attributes()->prot == "0"){
echo "<tr><td> ";
echo "<img src='http://view.light-speed.com//images/s_vent2/channel_0_empty.gif' />";
echo "<font color=\"#ffffff\">";
echo $subchannel->attributes()->name;
echo "</font>";
echo "</td></tr>";
}else{
echo "<tr><td> ";
echo "<img src='http://view.light-speed.com//images/s_vent2/channel_1_empty.gif' />";
echo "<font color=\"#ffffff\">";
echo $subchannel->attributes()->name;
echo "</font>";
echo "</td></tr>";
}
if($subchannel->client){
for ( $i = 0; $i < count($subchannel->client); $i++ ){
$client = $subchannel->client[ $i ];
if ( $client->attributes()->cid != $client->attributes()->cid )
continue;
echo "<tr><td> ";
echo "<img src='http://view.light-speed.com//images/s_vent2/player.gif' /><font color=\"#009e1a\">";
if($client->attributes()->admin == "1"){
echo $client->attributes()->name;
echo " <font color=\"#ff0000\">(Admin)</font>";
}else{
echo $client->attributes()->name;
}
echo "</td></tr>";
}
}
foreach($subchannel->channel as $subchannel2) {
if($subchannel2->attributes()->prot == "0"){
echo "<tr><td> ";
echo "<img src='http://view.light-speed.com//images/s_vent2/channel_0_empty.gif' />";
echo "<font color=\"#ffffff\">";
echo $subchannel2->attributes()->name;
echo "</font>";
echo "</td></tr>";
}else{
echo "<tr><td> ";
echo "<img src='http://view.light-speed.com//images/s_vent2/channel_1_empty.gif' />";
echo "<font color=\"#ffffff\">";
echo $subchannel2->attributes()->name;
echo "</font>";
echo "</td></tr>";
}
if($subchannel2->client){
for ( $i = 0; $i < count($subchannel2->client); $i++ ){
$client = $subchannel2->client[ $i ];
if ( $client->attributes()->cid != $client->attributes()->cid )
continue;
echo "<tr><td> ";
echo "<img src='http://view.light-speed.com//images/s_vent2/player.gif' /><font color=\"#009e1a\">";
if($client->attributes()->admin == "1"){
echo $client->attributes()->name;
echo " <font color=\"#ff0000\">(Admin)</font>";
}else{
echo $client->attributes()->name;
}
echo "</td></tr>";
}
}
foreach($subchannel2->channel as $subchannel3) {
if($subchannel3->attributes()->prot == "0"){
echo "<tr><td> ";
echo "<img src='http://view.light-speed.com//images/s_vent2/channel_0_empty.gif' />";
echo "<font color=\"#ffffff\">";
echo $subchannel3->attributes()->name;
echo "</font>";
echo "</td></tr>";
}else{
echo "<tr><td> ";
echo "<img src='http://view.light-speed.com//images/s_vent2/channel_1_empty.gif' />";
echo "<font color=\"#ffffff\">";
echo $subchannel3->attributes()->name;
echo "</font>";
echo "</td></tr>";
}
if($subchannel3->client){
for ( $i = 0; $i < count($subchannel3->client); $i++ ){
$client = $subchannel3->client[ $i ];
if ( $client->attributes()->cid != $client->attributes()->cid )
continue;
echo "<tr><td> ";
echo "<img src='http://view.light-speed.com//images/s_vent2/player.gif' /><font color=\"#009e1a\">";
if($client->attributes()->admin == "1"){
echo $client->attributes()->name;
echo " <font color=\"#ff0000\">(Admin)</font>";
}else{
echo $client->attributes()->name;
}
echo "</td></tr>";
}
}
}
}
}
}
echo "</table>";
?>
显示
- 大厅
- 渠道
- 子通道
- 子通道