Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> jak naprawic ponizszy kod?
Malinamaria
post
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
 
Start new topic
Odpowiedzi (1 - 8)
trzczy
post
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
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
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
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
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
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
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
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 (IMG:style_emoticons/default/wink.gif) Kwestia znajomości operatorów i zastosowanie odpowiedniego (IMG:style_emoticons/default/smile.gif)
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: 3.10.2025 - 03:46