我正在尝试将来自 Minecraft 服务器的数据输入到我的网页中,作为测试。这是代码:
<?php $host = "hub.cobalt-mc.com";
$port = 25565;
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$connected = socket_connect($socket, $host, $port);
if ($connected) {
$ping_start = microtime(true);
socket_send($socket, "\xFE", 1, 0);
$data = "";
$result = socket_recv($socket, &$data, 1024, 0);$ping_end = microtime(true);
socket_close($socket);
if ($result != false && substr($data, 0, 1) == "\xFF") {
$info = explode("\xA7", mb_convert_encoding(substr($data,1), "iso-8859-1","utf-16be"));
$serverName = substr($info[0], 1);
$playersOnline = $info[1];
$playersMax = $info[2];
$ping = round(($ping_end - $ping_start) * 1000);
echo "<table class=\"table table-hover\">
<th>Server Address</th>
<th>Status</th>
<th>Rank</th>
<th>Total DP</th>
<tr>
<td>$host:$ip</td>
if (($ping > '1000') || ($ping < '0')) {
echo "<td><span class=\"label label-success\">Online!</span></td>";
}
else {
echo "<td><span class=\"label label-success\">Online!</span></td>";
}
<td></td>
<td></td>
</tr>
<tr>
<td>$host:$ip</td>
<td></td>
<td></td>
<td></td>
</tr>
</table>";
}
else {
echo "<span style=\"color:#FF0000\">Error: </span>Failed to receive data";
}
} else {
echo "<span style=\"color:#FF0000\">Error: </span>Failed to send data";
}?>
我得到错误:
Parse error: syntax error, unexpected '>' in /home/mctronco/public_html/leaderboards/serverping.php on line 27
代码有问题吗?