Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> jak naprawic ponizszy kod?
Malinamaria
post 11.11.2017, 13:55:16
Post #1





Grupa: Zarejestrowani
Postów: 2
Pomógł: 0
Dołączył: 11.11.2017

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


01: $str1 = 'yabadabadoo';
02: $str2 = 'yaba';
03: if (strpos($str1,$str2)) {
04: echo "\"" . $str1 . "\" contains \"" . $str2 . "\"";
05: } else {
06: echo "\"" . $str1 . "\" does not contain \"" . $str2 . "\"";
07: }
Go to the top of the page
+Quote Post
trzczy
post 11.11.2017, 14:38:44
Post #2





Grupa: Zarejestrowani
Postów: 460
Pomógł: 49
Dołączył: 5.06.2011

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


http://php.net/manual/en/function.strpos.php#80363

Dodatkowo można też zastosować funkcję
Go to the top of the page
+Quote Post
Pyton_000
post 11.11.2017, 14:51:12
Post #3





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

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


A raczej: http://php.net/manual/en/function.strpos.p...os-returnvalues
Go to the top of the page
+Quote Post
trzczy
post 11.11.2017, 15:05:01
Post #4





Grupa: Zarejestrowani
Postów: 460
Pomógł: 49
Dołączył: 5.06.2011

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


Cytat(Pyton_000 @ 11.11.2017, 14:51:12 ) *

Ok tylko pojawia się pytanie, co ze zwróconą przez strpos wartością zrobić.
Go to the top of the page
+Quote Post
Pyton_000
post 11.11.2017, 15:13:13
Post #5





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

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


Jak to co? Co chcesz...
Go to the top of the page
+Quote Post
trzczy
post 11.11.2017, 15:16:21
Post #6





Grupa: Zarejestrowani
Postów: 460
Pomógł: 49
Dołączył: 5.06.2011

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


Sprawdzić, czy strpos zwraxa false, czy nie
  1. <?php
  2. $str1 = 'yabadabadoo';
  3. $str2 = 'yaba';
  4. if (is_int(strpos($str1,$str2))) {
  5. echo "\"" . $str1 . "\" contains \"" . $str2 . "\"";
  6. } else {
  7. echo "\"" . $str1 . "\" does not contain \"" . $str2 . "\"";
  8. }
Go to the top of the page
+Quote Post
Pyton_000
post 11.11.2017, 15:20:31
Post #7





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

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


  1. <?php
  2. $str1 = 'yabadabadoo';
  3. $str2 = 'yaba';
  4.  
  5. $msg = (strpos($str1, $str2) !== false)
  6. ? '"%s" contains "%s"'
  7. : '"%s" does not contains "%s"';
  8. sprintf($msg, $str1, $str2);
Go to the top of the page
+Quote Post
trzczy
post 11.11.2017, 15:22:36
Post #8





Grupa: Zarejestrowani
Postów: 460
Pomógł: 49
Dołączył: 5.06.2011

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


  1. !== false
było w linku w moim pierwszym poście ;p
Go to the top of the page
+Quote Post
Pyton_000
post 11.11.2017, 15:25:26
Post #9





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

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


W moim również było co zwraca wink.gif Kwestia znajomości operatorów i zastosowanie odpowiedniego smile.gif
Go to the top of the page
+Quote Post

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

 



RSS Wersja Lo-Fi Aktualny czas: 14.08.2025 - 13:39