Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] Funkcje drukujące tekst, różną wielkością liter
panksawery
post
Post #1





Grupa: Zarejestrowani
Postów: 4
Pomógł: 0
Dołączył: 8.06.2022

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


Witam. Prosiłbym o pomoc z 2 prostymi funkcjami. Mianowicie chciałbym aby pierwsza funkcja drukowała dowolny tekst małymi literami, a druga dokładnie ten sam tekst tylko, że wielkimi. Jestem laikiem i stanąłem na punkcie 2. Nie bardzo wiem jak wyciągnąć do drugiej funkcji wynik pierwszej i użyć na nim mb_strtoupper(). Z góry dzięki za pomoc (IMG:style_emoticons/default/wink.gif)

  1. <?php
  2. $drukuj = function(string $tekst) {
  3. print ($tekst);
  4. print PHP_EOL;
  5. };
  6.  
  7. $drukuj("DrUkOwAnIe MaŁyMi LiTeRaMi");
  8. $drukuj('i JeSzCZE RaZ mAłYmI LiTeRaMi');
  9.  
  10. function duzeLitery($drukuj) {
  11. mb_strtoupper($drukuj);
  12. print PHP_EOL;
  13. };
  14.  
  15. duzeLitery($drukuj);
  16. ?>
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Salvation
post
Post #2





Grupa: Zarejestrowani
Postów: 406
Pomógł: 73
Dołączył: 15.07.2014

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


  1. <?php
  2.  
  3. declare(strict_types=1);
  4.  
  5. function bigLetters(string $text): string
  6. {
  7. return mb_strtoupper($text);
  8. }
  9.  
  10. function smallLetters(string $text): string
  11. {
  12. return mb_strtolower($text);
  13. }
  14.  
  15. function printBigLetters(string $text): void
  16. {
  17. echo bigLetters($text) . PHP_EOL;
  18. }
  19.  
  20.  
  21. function printSmallLetters(string $text): void
  22. {
  23. echo smallLetters($text) . PHP_EOL;
  24. }
  25.  
  26. $text1 = 'DrUkOwAnIe DuŻyMi LiTeRaMi';
  27. $text2 = 'DrUkOwAnIe MaŁyMi LiTeRaMi';
  28.  
  29. printBigLetters($text1);
  30. printSmallLetters($text2);


Demo: https://3v4l.org/IWPDp

Ten post edytował Salvation 9.06.2022, 08:56:56
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: 12.10.2025 - 11:39