mardi, mars 19, 2024
Nom d'utilisateur : Mot de passe :
Home > Quickies > Calendrier PHP
[NEWS]
Envoyé par unreal
Il arrive souvent à ce qu'on ait besoin d'afficher un calendrier, alors voici un petit script prévu à cet effet. Il est multi-langue (il suffit de modifier la ligne setlocale), et parfaitement customisable.

<?php
$year = 2005;
$month = 7;

setlocale(LC_ALL, 'fr_FR.ISO8859-1');
echo (mycal($year, $month));

function mycal($year, $month) {
    $td = '<td>';
    $td_ = '</td>';
    $tr = '<tr>';
    $tr_ = '</tr>';
    $table = '<table>';
    $table_ = '</table>';

    $cal_header = strftime('%B, %Y', mktime(0, 0, 0, $month, 1, $year)) . "\n";

    $start_day = strftime('%u', mktime(0, 0, 0, $month, 1, $year));
    $days_in_month = date('j', mktime(0, 0, 0, $month + 1, 0, $year));

    $cal = "$table\n$tr";
    for ($i = 2 - $start_day ; $i <= 8 - $start_day ; $i++)
        $cal .= $td . ucfirst(strftime('%a', mktime(0, 0, 0, $month, $i, $year))) . $td_;
    $cal .= "$tr_\n$tr";

    $line_day = $start_day;
    $cal .= str_repeat($td . $td_, ($start_day - 1));

    for ($i = 1 ; $i <= $days_in_month ; $i++) {
        if ($line_day == 8) {
            $line_day = 1;
            $cal .= "$tr_\n$tr";
        }
        $cal .= $td . $i . $td_;
        $line_day++;
    }

    $cal .= "$tr_\n$table_";

    return("$cal_header\n<br /><br />\n$cal");
}
?>


Pour la démo (avec code source), c'est par ici !

Posté le 18/04/05 à 03:09

Calendrier PHP
Vous pourriez commenter si vous aviez un compte !