테스트 사이트 - 개발 중인 베타 버전입니다

시간별이미지출력 이것좀봐주세요!~~

지금 시간대 별로 이미지를 출력하려고하는데요!~
소스를 이렇게했는데!~

내용은 아침 08:00~09:00 시까지 onair이라는이미지가
점심 12:00~01:00 시까지 onair이라는이미지가
저녁 05:00~06:00 시까지 onair이라는이미지가

그외의시간은 offair 이라는 이미지가 뜨게하고싶은데 이렇게 하는게 맞는지 고수분들께서좀 봐주세요!~~~

<?php
$ctime = time();
$img = 0;

$achimStart = strtotime(date("Y-m-d"). "08:00");
$achimEnd  = strtotime(date("Y-m-d"). "09:00");

$bchimStart = strtotime(date("Y-m-d"). "12:00");
$bchimEnd  = strtotime(date("Y-m-d"). "01:00");

$cchimStart = strtotime(date("Y-m-d"). "05:30");
$cchimEnd  = strtotime(date("Y-m-d"). "06:00");

// 아침인지....
if($ctime >= $achimStart && $ctime <= $achimEnd) $img = 1;

// 점심인지....
if($ctime >= $bchimStart && $ctime <= $bchimEnd) $img = 1;

// 저녁인지....
if($ctime >= $cchimStart && $ctime <= $cchimEnd) $img = 1;

if($img == 1) echo "<img src=./img_u/onair.gif>";
else echo "<img src=./img_u/offair.gif>";

?>

[이 게시물은 관리자님에 의해 2011-10-31 17:12:10 PHP & HTML에서 이동 됨]

댓글 작성

댓글을 작성하시려면 로그인이 필요합니다.

로그인하기

댓글 2개

잘 하셨는데요. 로직이 거꾸로네요. Time 을 substr 이란 함수로 잘라서 쓰면
조금더 간편한 코드가 나올법했는데 말이죠. ㅎㅎ
<?php

switch( date('H')) {
case '08':
case '09':
case '12':
case '13':
case '17': if( date('i')<'30') break;
case '18': echo 'onair.gif';
}

?>

게시판 목록

프로그램

글쓰기