-2

5a-10a MF の放送中にストリーミング プレーヤーを表示し、放送中でないときに別のものを表示するページの一部を作成しようとしています。

これが私が今持っているものですが、機能していません。私はPHPがかなり新しいです。ありがとう!

<html>
<head>
<title>streaming</title>
</head>
<body>
<?php

//Get the current hour
$current_time = date(G);
//Get the current day
$current_day = date(l);

//Off air
if ($current_day == "Saturday" or $current_day == "Sunday" or ($current_time <= 5 && $current_time >= 10)) {
echo "We’re live Monday – Friday mornings. Check back then.";
}

// Display player
else {
echo "<a href="linktoplayer.html"><img src=http://www.psdgraphics.com/wp-content/uploads/2009/09/play.jpg></a>";
}


?>
</body>
</html>
4

3 に答える 3

4

#1。

このステートメントは常に FALSE になります。

($current_time <= 5 && $current_time >= 10)

正しい:

($current_time < 5 || $current_time >= 10)

#2。

これにより$current_time = date(G);$current_day = date(l);通知が出力されます。

Notice:  Use of undefined constant G - assumed 'G' in ...
Notice:  Use of undefined constant l - assumed 'l' in ...

正しい:

$current_time = date('G');
$current_day = date('l');

#3。

このコードecho "<a href="linktoplayer.html"><img src=http://www.psdgraphics.com/wp-content/uploads/2009/09/play.jpg></a>";は、PARSE ERROR も出力します。

Parse error: syntax error, unexpected 'linktoplayer' (T_STRING), expecting ',' or ';' in ...

出力したい場合は、文字列でエスケープ"する必要があります。\

echo "<a href=\"linktoplayer.html\"><img src=\"http://www.psdgraphics.com/wp-content/uploads/2009/09/play.jpg\"></a>";

または'代わりに使用します:

echo '<a href="linktoplayer.html"><img src="http://www.psdgraphics.com/wp-content/uploads/2009/09/play.jpg"></a>';

画像のpssrc属性は で囲む必要があります""

于 2012-09-26T21:54:08.053 に答える
4

2つのこと:

  1. 指摘されているように、あなたの時間ロジックはオフです。そのはず$current_time < 5 or $current_time >= 10)

  2. 日付関数に何かを与える場合、それは文字列でなければなりません。date(l)であるはずなので、エラーがスローされますdate('l')

編集:

本当にコードのベンチマークを行いたい場合idateは、整数を返すため、代わりに使用する必要があります。比較は次のようになります。

$current_time = idate('H');
$current_day = idate('w');

if ($current_day === 0 || $current_day === 6 || 
    $current_time < 5 || $current_time >= 10) {
    echo "We’re live Monday – Friday mornings. Check back then.";
}
于 2012-09-26T21:55:25.397 に答える
0

Ifこのようにステートメント構造を変更する必要があると思います

IF (on-air) 
THEN DisplayPlayer() 
ELSE echo "message saying Off Air"

こうすることで、オンライン中に誰かがそのサイトにアクセスしようとしたときに、プレーヤーをより速くヒットさせることができます。

これは、オンエア中の読み込み時間を短縮する最適化です。オフエアの場合は、2 つのステップを経ます。ロード時間を短縮したい場所に依存します

これは、@glavićが回答で書いたものに加えて使用する必要があります。

于 2012-09-26T21:59:59.043 に答える