Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] mktime, date - dodanie nazw miesięcy po polsku, [PHP] mktime, date - dodanie nazw miesięcy po polsku
monsarrat
post
Post #1





Grupa: Zarejestrowani
Postów: 23
Pomógł: 1
Dołączył: 29.02.2012
Skąd: Polska

Ostrzeżenie: (0%)
-----


Witam, proszę o dopisanie funkcji pozwalającej na wyświetlanie polskie nazwy miesięcy. Z góry dziękuję za pomoc.

  1.  
  2. <?php
  3. $month = (isset($_GET["m"]) && is_numeric($_GET["m"])) ? (int)$_GET["m"] : "";
  4. $year = (isset($_GET["y"]) && is_numeric($_GET["y"])) ? (int)$_GET["y"] : "";
  5.  
  6. if (strcmp($month, "") == 0 || strcmp($year, "") == 0)
  7. {
  8. $from = time();
  9. $info = getdate($from);
  10. $month = $info["mon"];
  11. $year = $info["year"];
  12. }
  13.  
  14. $from = mktime(0, 0, 0, $month, 1, $year);
  15. $to = mktime(0, 0, 0, ($month + 1 == 13) ? 1 : $month + 1, 1, ($month + 1 == 13) ? $year + 1 : $year);
  16.  
  17. ?>
  18.  
  19.  
  20. <h2><?php echo date('F Y', $from);?></h2>
  21.  


Ten post edytował monsarrat 22.11.2012, 10:26:43
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
monsarrat
post
Post #2





Grupa: Zarejestrowani
Postów: 23
Pomógł: 1
Dołączył: 29.02.2012
Skąd: Polska

Ostrzeżenie: (0%)
-----


pokombinowałem i roziwzniem jest
  1. setlocale(LC_ALL, 'pl_PL.UTF-8');

konieczne jest danie UTF-8 ze względu na poskie litery ń i ź

w całości działający kod wygląda tak, może komuś sie przyda... :

(IMG:http://i50.tinypic.com/2vl0jeh.jpg)

  1. <?php
  2.  
  3. setlocale(LC_ALL, 'pl_PL.UTF-8');
  4.  
  5. $month = (isset($_GET["m"]) && is_numeric($_GET["m"])) ? (int)$_GET["m"] : "";
  6. $year = (isset($_GET["y"]) && is_numeric($_GET["y"])) ? (int)$_GET["y"] : "";
  7.  
  8. if (strcmp($month, "") == 0 || strcmp($year, "") == 0)
  9. {
  10. $from = time();
  11. $info = getdate($from);
  12. $month = $info["mon"];
  13. $year = $info["year"];
  14. }
  15.  
  16. $from = mktime(0, 0, 0, $month, 1, $year);
  17. $to = mktime(0, 0, 0, ($month + 1 == 13) ? 1 : $month + 1, 1, ($month + 1 == 13) ? $year + 1 : $year);
  18.  
  19. ?>
  20.  
  21. <div align="center">
  22. <hr/>
  23.  
  24.  
  25. <h2><?php echo strftime("%B, %G",$from);?></h2>
  26.  
  27. <div>
  28. <a class="" href="index.php?y=<?php echo $year - 1; ?>&m=<?php echo $month; ?>">Poprzedni Rok</a>
  29. <a class="" href="index.php?y=<?php echo ($month - 1 == 0) ? $year - 1 : $year; ?>&m=<?php echo ($month - 1 == 0) ? 12 : $month - 1; ?>">Poprzedni Miesiąc</a>
  30. <a class="" href="index.php?y=<?php echo ($month + 1 == 13) ? $year + 1 : $year; ?>&m=<?php echo ($month + 1 == 13) ? 1 : $month + 1; ?>">Następny Miesiąc</a>
  31. <a class="" href="index.php?y=<?php echo $year + 1; ?>&m=<?php echo $month; ?>">Następny Rok</a>
  32. <?php
  33. $currentMonthInfo = getdate(time());
  34. ?>
  35.  
  36. <a class="" href="index.php?y=<?php echo $currentMonthInfo["year"]; ?>&m=<?php echo $currentMonthInfo["mon"]; ?>">Aktualny miesiąc</a>
  37. </div>
  38.  
  39.  


Pozdrawiam i dziękuje za pomoc.

Ten post edytował monsarrat 22.11.2012, 11:57:33
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 17.10.2025 - 03:25