带有PHP脚本的Kraken API会导致HTML页面变为空白

时间:2013-10-18 02:58:52

标签: php html api streaming

是否有人发现此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>&nbsp;</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回声中使用双引号,这是.....糟糕!但是,代码仍然有错误。该表显示标题,然后单个单元格未对齐。不知何故,第一列的图像显示为第一列标题的LEFT。我不明白为什么!

1 个答案:

答案 0 :(得分:1)

因为这是无效的表格标记

<table class="onlineList">
<th>
<td class="onlineStatus"><h3>Status</h3></td>
<td><h3>Streamer Name</h3></td>
<td><h3>Stream Title</h3></td>
</th>

<th>元素的行为类似于单元格,但您正在使用它而不是<tr>

试试这个:

<table class="onlineList">
<tr>
<td class="onlineStatus"><h3>Status</h3></td>
<td><h3>Streamer Name</h3></td>
<td><h3>Stream Title</h3></td>
</tr>