简体   繁体   English

XML链接到PHP数组

[英]XML link into a PHP array

I'm having trouble getting this page ( http://ventrilostatus.net/xml/V98.DARKSTARLLC.COM:3789/ ) to array into php. 我在将此页面( http://ventrilostatus.net/xml/V98.DARKSTARLLC.COM:3789/ )整理成php时遇到麻烦。 I'm not very good with xml and I currently can only get it to display: Server Channel Channel Channel (etc) 我对xml不太满意,目前只能显示它:Server Channel Channel Channel(等)

Could anyone help me get it to show the channel name and the users? 有人可以帮我显示频道名称和用户吗? if there are not clients when you look at it it will be: 如果您没有客户,它将是:

<client admin="1" cid="994" phan="0" ping="186" sec="56935" name="WHERE USER'S NAME HIS HERE" comm=""/>

U can use the simple_xml functions of PHP to load the xml file into a class. U可以使用PHP的simple_xml函数将xml文件加载到类中。

http://php.net/manual/de/book.simplexml.php http://php.net/manual/de/book.simplexml.php

Edit with an example: 编辑示例:

// 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"
}

I think it's clear now. 我认为现在很清楚。 You have to iterate through every channel and look for clients. 您必须遍历每个渠道并寻找客户。

sorry this is the code I updated: 抱歉,这是我更新的代码:

<?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>&nbsp;&nbsp;";
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>&nbsp;&nbsp;";                                            
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>&nbsp;&nbsp;";
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 "&nbsp;<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>&nbsp;&nbsp;&nbsp;&nbsp;";
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>&nbsp;&nbsp;&nbsp;&nbsp;";                                            
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>&nbsp;&nbsp;&nbsp;&nbsp;";
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 "&nbsp;<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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";                                            
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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
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 "&nbsp;<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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";                                            
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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
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 "&nbsp;<font color=\"#ff0000\">(Admin)</font>";
     }else{
     echo $client->attributes()->name;
     }

echo "</td></tr>";
}
}
}

}
}
}
echo "</table>";
?>

which shows 这表现了

  • lobby 前厅
  • channel 渠道
  • subchannel 子信道
  • subchannel 子信道

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM