Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] problem z bardzo prostą funkcją
linx
post
Post #1





Grupa: Zarejestrowani
Postów: 100
Pomógł: 3
Dołączył: 25.06.2007

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


Witam,
mam problem ze stworzeniem bardzo prostej funkcji:

  1. <?php
  2. function miesiac_nazwa($tekst) {
  3.        $tekst = str_replace('1', STYCZEN, $tekst);
  4.        $tekst = str_replace('2', LUTY, $tekst);
  5.        $tekst = str_replace('3', MARZEC, $tekst);
  6.        $tekst = str_replace('4', KWIECIEN, $tekst);
  7.        $tekst = str_replace('5', MAJ, $tekst);
  8.        $tekst = str_replace('6', CZERWIEC, $tekst);
  9.        $tekst = str_replace('7', LIPIEC, $tekst);
  10.        $tekst = str_replace('8', SIERPIEN, $tekst);
  11.        $tekst = str_replace('9', WRZESIEN, $tekst);
  12.        $tekst = str_replace('10', PAZDZIERNIK, $tekst);
  13.        $tekst = str_replace('11', LISTOPAD, $tekst);
  14.        $tekst = str_replace('12', GRUDZIEN, $tekst);
  15.        return $tekst;
  16. }
  17. ?>


funkcja fajnie działa do momentu kiedy wartość są od 1-9, kiedy wartość są od 10-12 to zawsze wyświetla się styczeń.

Prosił bym o jakieś wskazówki.
Za pomoc z góry dziękuje.
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
linx
post
Post #2





Grupa: Zarejestrowani
Postów: 100
Pomógł: 3
Dołączył: 25.06.2007

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


Są to wartości pobierane z getdate():

  1. <?php
  2.  
  3. function miesiac_nazwa($tekst) {
  4.       $tekst = str_replace('1', STYCZEN, $tekst);
  5.       $tekst = str_replace('2', LUTY, $tekst);
  6.       $tekst = str_replace('3', MARZEC, $tekst);
  7.       $tekst = str_replace('4', KWIECIEN, $tekst);
  8.       $tekst = str_replace('5', MAJ, $tekst);
  9.       $tekst = str_replace('6', CZERWIEC, $tekst);
  10.       $tekst = str_replace('7', LIPIEC, $tekst);
  11.       $tekst = str_replace('8', SIERPIEN, $tekst);
  12.       $tekst = str_replace('9', WRZESIEN, $tekst);
  13.       $tekst = str_replace('10', PAZDZIERNIK, $tekst);
  14.       $tekst = str_replace('11', LISTOPAD, $tekst);
  15.       $tekst = str_replace('12', GRUDZIEN, $tekst);
  16.       return $tekst;
  17. }
  18.  
  19.  
  20. $czas = getdate();
  21. $miesiac = $czas['mon'];
  22.  
  23. echo miesiac_nazwa($miesiac);
  24.  
  25. ?>
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: 28.12.2025 - 13:05