有人看到这个 HTML/PHP 代码有问题吗?我一添加它,页面就显示为空白,浏览器根本没有读取任何源代码。即使我用它评论它仍然是空白的!
<body>
<?php
function getInfo ($a)
{
$online = 'images/streamRing/online.png';
$offline = 'images/streamRing/offline.png';
$size = '20';
$array = json_decode(file_get_contents('https://api.twitch.tv/kraken/streams/'.strtolower($a)), true);
if ($array['stream'] != NULL)
{
$channelTitle = $array['stream']['channel']['display_name'];
$streamTitle = $array['stream']['channel']['status'];
$currentGame = $array['stream']['channel']['game'];
echo "<tr><td class='onlineStatus'><img src='$online' height='$size' width='$size' alt='Online' />Online</td>";
echo "<td>$channelTitle</td><td>$streamTitle</td></tr>";
}
else
{
echo "<tr><td class='onlineStatus'><img src='$offline' height='$size' width='$size' alt='Offline' />Offline</td>";
echo "<td>$a</td><td> </td></tr>";
}
}
?>
....(稍后在页面中...) ....
<table class="onlineList">
<th>
<td class="onlineStatus"><h3>Status</h3></td>
<td><h3>Streamer Name</h3></td>
<td><h3>Stream Title</h3></td>
</th>
<?php
$streamer_1 = 'xxxx';
$streamer_2 = 'yyyy';
getInfo($streamer_2);
getInfo($streamer_1);
?>
</table>
php 代码是使用 Kraken API 开发的,这里很简单地演示:http: //www.incendiarymedia.org/twitch/status.php
编辑:我注意到并修复了中断错误。我在 php echo 中使用了双引号,这很糟糕!但是,代码仍然有错误。该表显示标题,然后各个单元格未对齐。不知何故,第一列的图像显示在第一列标题的左侧。我不明白为什么!