Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP] problem z przetwarzaniem stringów
neverever
post 15.11.2008, 11:29:53
Post #1





Grupa: Zarejestrowani
Postów: 278
Pomógł: 44
Dołączył: 17.02.2004
Skąd: Wieliczka

Ostrzeżenie: (10%)
X----


mam tablice z nazwami miast/lotnisk przykładowo:
Cytat
Warszawa (Okęcie)
Wellington
Springfield (Springfield)
Seattle (Tacoma International)
Port Angeles (Port Angeles)


problem w tym że muszę usunąć duplikaty - jeżeli w nawiasie jest to samo co przed to nawias wylatuje.

Czyli bez zmian pozostają
Cytat
Warszawa (Okęcie)
Wellington
Seattle (Tacoma International)


a
Cytat
Springfield (Springfield)
Port Angeles (Port Angeles)


zmienia na
Cytat
Springfield
Port Angeles


Jak coś takiego zrobić?

Ten post edytował neverever 15.11.2008, 11:31:36


--------------------
neverever
Go to the top of the page
+Quote Post
bim2
post 15.11.2008, 11:46:59
Post #2





Grupa: Zarejestrowani
Postów: 1 873
Pomógł: 152
Dołączył: 9.04.2006
Skąd: Berlin

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


  1. <?php
  2. $tmp = explode(' (', $lotnisko);
  3. if($tmp[0]==str_replace(')', '', $tmp[1]))
  4. {
  5. $lotnisko == $tmp[0];
  6. }
  7. ?>


Ten post edytował bim2 15.11.2008, 11:47:10


--------------------
Go to the top of the page
+Quote Post
-gox-
post 15.11.2008, 11:55:53
Post #3





Goście







  1. <?php
  2.  
  3. $lotniska = array();
  4. $lotniska = array_values($lotniska);
  5. $count = count($lotniska);
  6. for($i=0;$i<$count;$++) {
  7.    preg_match("#^[\tr\n ]*([a-zA-Z]+)[\tr\n ]*(([a-zA-Z]+))[ ]*$#", $lotniska[$i], $match)
  8.    if ( $match[1] == $match[2] )
  9.        unset($lotniska[$i]);
  10. }
  11.  
  12. ?>
Go to the top of the page
+Quote Post
-gox-
post 15.11.2008, 11:57:42
Post #4





Goście







pow. przyklad jest bledny..

  1. <?php
  2.  
  3. $lotniska = array();
  4. $lotniska = array_values($lotniska);
  5. $count = count($lotniska);
  6. for($i=0;$i<$count;$++) {
  7.    if ( preg_match("#^[\tr\n ]*([a-zA-Z]+)[\tr\n ]*(([a-zA-Z]+))[ ]*$#", $lotniska[$i], $match) {
  8.        if ( $match[1] == $match[2] )
  9.            $lotniska[$i] = $match[1];
  10.    }
  11. }
  12.  
  13. ?>
Go to the top of the page
+Quote Post
bim2
post 15.11.2008, 13:01:17
Post #5





Grupa: Zarejestrowani
Postów: 1 873
Pomógł: 152
Dołączył: 9.04.2006
Skąd: Berlin

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


Jeny, ale po co w to pregmatcha angażować? Troche przekombinowane.


--------------------
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 - 00:18