2012-05-29 70 views
0

我需要生成一个列表的HTML代码,在当天之后的10个开放日的列表中,开放日期是指工作日(m,t,w,t和f),我是使用下面的函数将日期翻译法语:基于当前日期的日期计数器

function f_date() { 
    $temps = time(); 
    $jours = array('Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'); 
    $jours_numero = date('w', $temps); 
    $jours_complet = $jours[$jours_numero]; 
    $NumeroDuJour = date('d', $temps); 
    $mois = array(' ', 'Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre'); 
    $mois_numero = date("n", $temps); 
    $mois_complet = $mois[$mois_numero]; 
    $an = date('Y', $temps); 
    $fr_temps = "$jours_complet, $NumeroDuJour $mois_complet $an"; 
    return "$fr_temps"; 
} 
echo "<br/>".f_date(); 

,我想产生以下结果:

<select name="ladate"> 
    <option selected="selected" value="Mardi, 29 mai 2012">29 mai 2012</option> 
    <option value="Mercredi, 30 mai 2012">30 mai 2012</option></select> 
    .... 
    <option value="Vendredi, 15 juin 2012">15 juin 2012</option></select> 
</select> 

请告诉我,如果你需要更多的信息。

谢谢。

+0

这里有什么问题?你有什么麻烦? –

+0

使用哪些php代码,考虑php函数,以生成当天的下列10个工作日。问题是服务器没有更新版本的PHP,所以我需要使用这个PHP函数进行翻译,并生成HTML ...并且我不知道如何继续:/ – Zatla00

回答

0

只需创建一个循环,将日数增加到10并忽略所有非开放日(周六,周日)。 date('N')是检测给定日期的工作日的朋友。

<?php 
$i = $openDay = 0; 
while($openDay < 10) { 
    $i++; 
    $time = strtotime('+'.$i.' days'); 
    $day = date('N', $time); 

    if ($day == 6 or $day == 7) { // ignore Saturdays and Sundays 
    continue; 
    } 

    echo f_date($time).'<br>'; 
    $openDay++; 
} 

你也必须修改date_f()功能使用$temps作为参数。

<?php 
function f_date($temps = null) { 
    // $temps = time(); 
    // ... 
} 
2

由于您只是在寻找MTWTF,并且您希望在接下来的10天内,您总是可以安全地查找接下来的14天,而忽略周末,那样会有10天的时间。它不适用于假期或类似的事情,但如果您需要这样做,您可以更改它。我在这里给你的伪代码,我将离开所有的阵列映射和文本输出到您

for ($days_to_add : 1 to 14) { 
    $new_date = date_add($days_to_add); 

    // check the day of the week 
    if (date('N', $new_date) >= 6) { 
     // ignore it, it's a weekend 
     continue; 
    } 

    // output the option tag for $new_date 
    echo "<option ... </option>" 
} 

这依赖于10 14天的假设,如果你想改变这个数字你可以添加某种计数器,并且只在计算周日/非假期时增加计数器

+0

感谢@mattedgod,但我认为不理解你的代码,并没有足够的知识来完成它;;(这是因为我使用这个php函数,我发现通过谷歌搜索:/ – Zatla00

+0

什么部分你不明白吗? –

+0

输出部分,我使用的代码波纹管在它的作品。 – Zatla00