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

时间:2022-10-21 10:52:58

I am working on a php project in which I want to show data in following way using PHP.

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

So when its 'X' day, PHP will display contents of a certain div element along with its CSS effects.

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

Example here are the variables/info:

这里的例子是变量/信息:

Title : What to Eat ?

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

Note: I want to keep the time as per Indian standard time [IST]

注意:我想按照印度标准时间[IST]保留时间

So when the day is Monday,

所以当这一天是星期一

It will display below:

它将显示如下:

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

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

When its tuseday it will display:

当它的tuseday它将显示:

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

When its Wednesday it will display:

星期三它将显示:

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

How do i achieve the above please help me, what php code to use for it or is then a more easy way to it. I want to make such thing for a whole week display [Mon -Sunday]

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

2 个解决方案

#1


1  

You can just use array in this operation. Consider this as an example:

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

<?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>

#2


0  

Something like this using PHP DATE()

使用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>";
    }
?>

#1


1  

You can just use array in this operation. Consider this as an example:

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

<?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>

#2


0  

Something like this using PHP DATE()

使用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>";
    }
?>