sarudansei Posted March 1, 2005 Share Posted March 1, 2005 Avec un script php est-ce qu'il est possible (et de quelle façon) d'echo un résultat de ce style : (Résultat si j'exécute le script aujourd'hui ou tout autre jour de la semaine) : - Lundi 28 février - Mardi 01 mars - Mercredi 02 mars - Jeudi 03 mars - Vendredi 04 mars En gros sortir une semaine en fonction du jour même... Je sais récupérer le numéro de la semaine, le jour dans une semaine mais je ne sais pas comment les mettre en relation... Merci d'avance ! Link to comment Share on other sites More sharing options...
theocrite Posted March 1, 2005 Share Posted March 1, 2005 Salut, ce que je ferais : Tu récupère le jour en question au format timestamp (comme time()). Tu teste le jour de la semaine et tu recule d'autant (0 pour lundi, 1 pour mardi etc) Ensuite, tu fais un une boucle. Par exemple, tu es mardi : for ($i = -1; $i < 6; $i++) { echo date("l d F",time()+$i*24*3600)."<br \>"; } Link to comment Share on other sites More sharing options...
sarudansei Posted March 1, 2005 Author Share Posted March 1, 2005 Oki je vois le concept, merci beaucoup ça a l'air de fonctionner... Pour tous les cas de jour j'exécute ça : if(date("w", time())==1){ for ($i = 0; $i <= 6; $i++) { echo date("l d F",time()+$i*24*3600)."<br \>"; } }elseif(date("w", time())==2){ for ($i = -1; $i <= 5; $i++) { echo date("l d F",time()+$i*24*3600)."<br \>"; } }elseif(date("w", time())==3){ for ($i = -2; $i <= 4; $i++) { echo date("l d F",time()+$i*24*3600)."<br \>"; } }elseif(date("w", time())==4){ for ($i = -3; $i <= 3; $i++) { echo date("l d F",time()+$i*24*3600)."<br \>"; } }elseif(date("w", time())==5){ for ($i = -4; $i <= 2; $i++) { echo date("l d F",time()+$i*24*3600)."<br \>"; } }elseif(date("w", time())==6){ for ($i = -5; $i <= 1; $i++) { echo date("l d F",time()+$i*24*3600)."<br \>"; } }elseif(date("w", time())==7){ for ($i = -6; $i <= 0; $i++) { echo date("l d F",time()+$i*24*3600)."<br \>"; } } Pour aujourd'hui ça marche, ça vous semble correct ? Link to comment Share on other sites More sharing options...
theocrite Posted March 1, 2005 Share Posted March 1, 2005 Après avoir un peu réfléchi, c'est plus simple que je ne le pensais. $start = -(date("w")+6)%7; for ( $i=0; $i<7; $i++, $start++) { echo date("l d F",time()+$start*24*3600)."<br \>"; } EDIT : c'est plus simple avec des variables. Ta solution est un peu crade. Link to comment Share on other sites More sharing options...
sarudansei Posted March 1, 2005 Author Share Posted March 1, 2005 Ouaip tu as raison !!! Merci beaucoup pour cette réponse Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.