Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Wyswietlanie co drugiego znaku.
Domson502
post
Post #1





Grupa: Zarejestrowani
Postów: 10
Pomógł: 0
Dołączył: 16.05.2016

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


function everySecondCharacter($input) {
$output = '';

dump($output);
}

everySecondCharacter('War, has never been so much fun.');
everySecondCharacter('All You Need Is Love.');
everySecondCharacter('Heard ten thousand whispering and nobody listening.');




Jak z tych 3 zdan wyciagnac co 2 znak ? Wiem jak wyciagac powiedzmy 5 pierwszych znakow.
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 9)
Arcioch
post
Post #2





Grupa: Zarejestrowani
Postów: 324
Pomógł: 110
Dołączył: 18.09.2012

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


Użyj str_split() i wybierz co 2 element tablicy (IMG:style_emoticons/default/smile.gif)

Ten post edytował Arcioch 16.05.2016, 09:22:17
Go to the top of the page
+Quote Post
Pyton_000
post
Post #3





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

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


np. tak.

  1. $string = "Raz dwa trzy";
  2.  
  3. for($i = 0,$len = strlen($string); $i<$len; $i++) {
  4. if($i%2) {
  5. echo $string[$i];
  6. }
  7. }
Go to the top of the page
+Quote Post
trueblue
post
Post #4





Grupa: Zarejestrowani
Postów: 6 807
Pomógł: 1828
Dołączył: 11.03.2014

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


  1. $string = "Raz dwa trzy";
  2.  
  3. for($i=0;$i<strlen($string);$i+=2){
  4. echo $string[$i];
  5. }
Go to the top of the page
+Quote Post
Domson502
post
Post #5





Grupa: Zarejestrowani
Postów: 10
Pomógł: 0
Dołączył: 16.05.2016

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


Cytat(Pyton_000 @ 16.05.2016, 10:21:52 ) *
np. tak.

  1. $string = "Raz dwa trzy";
  2.  
  3. for($i = 0,$len = strlen($string); $i<$len; $i++) {
  4. if($i%2) {
  5. echo $string[$i];
  6. }
  7. }



Dzieki wielkie ;D

A jeszcze jedno pytanko. Wyswietlam to dump($input[$i]); I problem jest taki ze wyswietla mi kazdy znak linie nizej. Jak zrobic zeby do kazdego zdania znaki byly wyswietlanie w 1 lini. Zgaduje ze jest to proste ale teraz zglupialem. Z gory dzieki ;D
Go to the top of the page
+Quote Post
Arcioch
post
Post #6





Grupa: Zarejestrowani
Postów: 324
Pomógł: 110
Dołączył: 18.09.2012

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


  1. <?php
  2.  
  3. function everySecondCharacter($input) {
  4. $output = '';
  5. for($i=0;$i<strlen($input);$i+=2){
  6. $output .= $input[$i];
  7. }
  8. return $output;
  9. }
  10.  
  11. echo everySecondCharacter('War, has never been so much fun.');


Nie dump a echo (IMG:style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post
Domson502
post
Post #7





Grupa: Zarejestrowani
Postów: 10
Pomógł: 0
Dołączył: 16.05.2016

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


Ogarnalem juz. Wystarczylo dac
  1. function everySecondCharacter($input) {
  2. $output = '';
  3.  
  4. for ($i = 0; $i < strlen($input); $i+=2) {
  5. $output .= $input[$i];
  6. }
  7. dump($output);
  8. }
  9.  
  10. everySecondCharacter('War, has never been so much fun.');
  11. everySecondCharacter('All You Need Is Love.');
  12. everySecondCharacter('Heard ten thousand whispering and nobody listening.');

  1. $output .= $input[$i];


Ten post edytował Domson502 16.05.2016, 11:21:48
Go to the top of the page
+Quote Post
com
post
Post #8





Grupa: Zarejestrowani
Postów: 3 034
Pomógł: 366
Dołączył: 24.05.2012

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


dajesz nam nie określona funkcje dump wiec skąd mamy wiedzieć czym ona jest (IMG:style_emoticons/default/wink.gif)
Go to the top of the page
+Quote Post
Pyton_000
post
Post #9





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

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


pewnie z symfony (IMG:style_emoticons/default/wink.gif)
Go to the top of the page
+Quote Post
mariolita
post
Post #10





Grupa: Zarejestrowani
Postów: 116
Pomógł: 10
Dołączył: 24.04.2015

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


  1. $ourString = "http://forum.php.pl";
  2.  
  3. $policzZnaki = strlen($ourString);
  4.  
  5. $wynik = "";
  6.  
  7. $i = 1;
  8.  
  9. while ($i <= ($policzZnaki - 1)) {
  10.  
  11. $wynik = $wynik.$ourString[$i];
  12.  
  13. $i = $i + 2;
  14.  
  15. }
  16.  
  17. echo $wynik;
Go to the top of the page
+Quote Post

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: 9.10.2025 - 14:07