jQuery检测PHP的星期几

I have this jQuery script that would detect the day of the week, and display the associated ID.

I was wondering, how can I achieve the same thing in PHP?

<script type="text/javascript"> $(document).ready(function() { 
    today=new Date() 
    thisDay=today.getDay()

    $("#mon").hide();
    $("#tue").hide();
    $("#wed").hide();
    $("#thu").hide();
    $("#fri").hide();
    $("#sat").hide();

    if (thisDay == 1){ $("#mon").show(); }
    if (thisDay == 2){ $("#tue").show(); }
    if (thisDay == 3){ $("#wed").show(); }
    if (thisDay == 4){ $("#thu").show(); }
    if (thisDay == 5){ $("#fri").show(); }
    if (thisDay == 6){ $("#sat").show(); }
}); </script>

Thanks.

Just rewrote this to me more clear, got a little wordy before. You can use an array with the ids you are using along with date('w') to write styles that will hide or show a div depending on which day it is.

opening markup:

<!DOCTYPE html>
<html>
<head>
<style>

Now create your array and write some styles based on what day it is.

$days = array('sun','mon','tue','wed', 'thu', 'fri', 'sat' );

foreach($days as $index=>$dayId){
   $display = $index == date('w') ? 'block' : 'none'; 
   echo '#'.$dayId.'{display:'.$display.';}';  
}

now close the style tag and begin the rest of the document.

</style>
</head>
<body>

I used date('w') instead of N as it starts at 0 and makes it easier to work with an array.

One more thing to add, make sure your timezone is set correctly or you could experience some undesired results.

You can simply do it like this:

  <?php 
        $week_day_as_number = date("N"); //e.g. 6

So the weekday is a number from 1 (Monday) to 7 (Sunday)

or you can do this:

  <?php
       $week_day_as_string = date("l"); //e.g. Saturday

So the result will be from: Monday - Sunday