动态显示一个月的日期名称 - PHP [重复]

This question already has an answer here:

I am looping the days of the current month and I want to display weekdays of the current month as well but i dont know.

//showing the days number of the current month
$currentDays = date('d');
for($i=1;$i<=$currentDays;$i++)
{
  //print the day number
  echo $i.'
';
}
</div>

You can use strtotime to get the timestamp of that specific day and then with that get the weekday name.

$days = date( 'd' );
$month = date( 'n' );

for ( $day = 1; $day <= $days; $day++ )
    echo $day, ' is ', date( 'l', strtotime( $month . '/' . $day ) ), '
';

To get a different weekday name for translations whatsoever, you must build your own array and get it through from there by changing the lowercase L to lowercase W, which will return you a weekday integer.

$weekdays = array( "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" );
$days = date( 'd' );
$month = date( 'n' );

for ( $day = 1; $day <= $days; $day++ )
    echo $day, ' is ', $weekdays[ date( 'w', strtotime( $month . '/' . $day ) ) ], '
';

Keep in mind that you are using lowercase D in your days-variable, which means it will only count the days until today. You can use lowercase T to loop through all days of the specified month.

The alternative is to use mktime as shown in another answer related to this question.

In addition, instead of defining weekday names by yourself, you could simply set the locale setting to your choosing and strftime the weekday name (%A).

<?php
$current_month = date("M");
$first_day_this_month = date('01');
$last_day_this_month  = date('t');
$st_result = '';
for($i=$first_day_this_month; $i<=$last_day_this_month; $i++ ){
    $day = '';
    $day = date("l", mktime(0, 0, 0, 5, $i, 2015));
    if($day == 'Saturday' || $day == 'Sunday'){continue;}
    else{$st_result = $st_result .','.$i;}
}
echo $st_result ;
?>

</div>