2014-10-03 48 views
1

我无法将此页面(http://ventrilostatus.net/xml/V98.DARKSTARLLC.COM:3789/)排列到php中。我不是很好的XML和我目前只能得到它显示: 服务器 通道 通道 通道 (ETC)将XML链接到PHP数组中

谁能帮我把它显示频道名称和用户? 如果没有客户,当你看它这将是:

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

您可以使用XML-PHP库将有效的XML代码转换为php对象或数组。 – 2014-10-03 16:48:40

回答

0

抱歉,这是我更新的代码:

<?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>"; 
?> 

表示

  • 大厅
  • 通道
  • 子信道
  • 子信道
0

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

我觉得现在很清楚。您必须遍历每个渠道并寻找客户。

+0

就像我说过的,我用xml不太好,我其实已经试过了。我的问题是我唯一能得到它的发布服务器 - 通道 - 通道 - 通道 - 等,因为XML心不是服务器名称 CHANNEL NAME我无法弄清楚如何获得的信息。 – user2002716 2014-10-03 17:23:53

+0

您可以通过每一个孩子的对象迭代,你可以用$ obj-访问标签的所有属性>属性() - >属性。如果你想拥有用户,用foreach循环迭代每个对象。 – Tyr 2014-10-03 18:56:12

+0

那正是我需要知道的,非常感谢! – user2002716 2014-10-05 15:37:28