Create Custom Calendar Using PHP

Apr 13, 2015, by php team

images
Nowadays web users would like to provide online dynamic calendar. An online calendar can be used for events, upcoming product and anything else you can think of. I’ve taken some time to completely rewrite the PHP event calendar so that I may share it with you.

PHP Code as follows :

<?php
function custom_calendar($mon,$year){

$custom = ‘<table>’;
$head = array(‘Sun’,’Mon’,’Tues’,’Wed’,’Thus’,’Fri’,’Sat’);
$custom.= ‘<tr ><td >’.implode(‘</td><td >’,$head).'</td></tr>’;

$run_day = date(‘w’,mktime(0,0,0,$mon,1,$year));
$days_in_month = date(‘t’,mktime(0,0,0,$mon,1,$year));
$days_in_week = 1;
$count_day = 0;
$dates_array = array();

$custom.= ‘<tr >’;

for($x = 0; $x < $run_day; $x++):
$custom.= ‘<td > </td>’;
$days_in_week++;
endfor;

for($list_day = 1; $list_day <= $days_in_month; $list_day++):
$custom.= ‘<td >’;

$custom.= ‘<div >’.$list_day.'</div>’;
$custom.= str_repeat(‘<p> </p>’,2);

$custom.= ‘</td>’;
if($run_day == 6):
$custom.= ‘</tr>’;
if(($count_day+1) != $days_in_month):
$custom.= ‘<tr >’;
endif;
$run_day = -1;
$days_in_week = 0;
endif;
$days_in_week++; $run_day++; $count_day++;
endfor;

if($days_in_week < 8):
for($x = 1; $x <= (8 – $days_in_week); $x++):
$custom.= ‘<td > </td>’;
endfor;
endif;

$custom.= ‘</tr>’;

$custom.= ‘</table>’;

return $custom;
}
echo ‘<h3>April 2015</h3>’;
echo custom_calendar(4,2015);
echo ‘<h3>May 2015</h3>’;
echo custom_calendar(5,2015);
?>

title