如何使用PHP显示每周特定日期的特定div内容?

时间:2014-04-28 04:20:54

标签: php css wordpress html dayofweek

我正在开发一个php项目,我希望使用PHP以下列方式显示数据。

因此,当它'X'天时,PHP将显示某个div元素的内容及其CSS效果。

这里的例子是变量/ info:

Title : What to Eat ?

Monday - eggs, bread, turkey <br/>
Tuesday - oats, rye, wheat bread<br/>
Wednesday - Milk , chicken, fish<br/>

注意:我希望按照Indian standard time [IST]

保留时间

所以当这一天是Monday时,

它将显示如下:

What to Eat ?<br/>
eggs, bread, turkey 

[this will be the content of monday and css will be used for styling it in div]

当它的tuseday显示时:

What to Eat ?<br/>
oats, rye, wheat bread

星期三它将显示:

What to Eat ?<br/>
Milk , chicken, fish

我如何实现上述请帮助我,使用什么PHP代码,或者是一个更简单的方法。 我希望整整一周显示[Mon -Sunday]

2 个答案:

答案 0 :(得分:1)

您可以在此操作中使用数组。以此为例:

<?php

$food = array(
    'Monday' => 'Eggs, Bread, Turkey',
    'Tueday' => 'Oats, Rye, Wheat Bread',
    'Wednesday' => 'Milk, Ckicken, Fish',
    'Thursday' => 'Eggs, Bread, Turkey',
    'Friday' => 'Oats, Rye, Wheat Bread',
    'Saturday' => 'Milk, Ckicken, Fish',
);

// use date function, then you can use this as a 'key' on the array
$day_today = date('l');

?>

<!-- HTML -->

<p>What do eat</p>
<p><?php echo $food[$day_today]; ?></p>

答案 1 :(得分:0)

使用PHP DATE()

这样的事情
<?php
    date_default_timezone_set('Asia/Kolkata');
    $day = date("l");
    if( $day == "Monday" ){
        echo "<div>Some content for monday</div>";
    } else if($day == "Tuesday" ){
        echo "<div>Some content for Tuesday</div>";
    } else if($day == "Wednesday" ){
        echo "<div>Some content for Wednesday</div>";
    }
?>